Absent the use of =~
or !~
,
/.../
is short for
$_ =~ m/.../
so
/\Q$prev\E/ !~ /\Q$ww[0]\E/
is short for
($_ =~ /\Q$prev\E/) !~ /\Q$ww[0]\E/
which is equivalent to one of the following depending on whether the left regex match succeeds or not:
"" !~ /\Q$ww[0]\E/
"1" !~ /\Q$ww[0]\E/
You simply want:
$prev !~ /\Q$ww[0]\E/ # $ww[0] doesn't contains $prev
If you actually want
$prev !~ /^\Q$ww[0]\E\z/ # $ww[0] isn't equal to $prev
then you can simplify that to
$prev ne $ww[0] # $ww[0] isn't equal to $prev
By the way, always use use strict; use warnings;
. It may have identified a problem here (but not necessarily, depending on the value of $_
).