use strict; use warnings; my @vars = ('quit','quirly cat', 'cat queue','granit'); print ("any string 'qu' followed by 'it'\n"); foreach (@vars) { if ($_ =~ /qu(?=it)/) { print ("found <$_>\n"); } else { print ("no match for <$_>\n"); } } print ("\nany string 'qu' not followed by 'it'\n"); foreach (@vars) { if ($_ =~ /qu(?!it)/) { print ("found <$_>\n"); } else { print ("no match for <$_>\n"); } }