否定正则表达式模式匹配

Negating a regex pattern match

有没有办法用下面的模式匹配语句来否定 elsif 语句,比如 $ip != $testip?

我知道 != 只适用于整数,我只是想解释一下我想要的:与 != 相同的功能,但在模式匹配时适用于字符串。

if ( $testip =~ /$ip/ ) {
    $frequency++;
}
elsif ( $ip ne $testip ) {

要否定匹配,可以使用

$testip !~ /$ip/

但不需要知道,你可以直接否定运算符

not $testip =~ /$ip/

但是为什么呢? else 分支仅在 if 条件 returns 为假时执行。