Perl Question

Perl regex hitting condition when not matching

I am checking a status of a program and acting apon it.

So I either receive all, local or an error.

However upon checking it with my

regex
I am always hitting the condition even when it doesn't match.

if ($pri !~ /local/ || $pri !~ /all/) {
print $pri."\n";
print "[PRIMARY] Heartbeat is not responding correctly \n";
$status++;
}


Above print displays as:

perl test.pl -p xx.xx.xx.xx -s xx.xx.xx.xx
all
[PRIMARY] Heartbeat is not responding correctly


And a dump looks like

perl test.pl -p xx.xx.xx.xx -s xx.xx.xx.xx
$VAR1 = 'all';
[PRIMARY] Heartbeat is not responding correctly


Am I missing something obvious? To me the condition should be skipped as the value is all.

Any feedback would be appreciated.

Answer

The regexp is almost fine, you just used wrong logical operator - or. It should be and:

if ($pri !~ /local/ && $pri !~ /all/) {
    ...

Also for regexp consider surrounding by ^ and $ to have full string match.