my $regex=qr{(?:(?:\Q$nameOne\E).*(?:\Q$nameTwo\E)|(?:\Q$nameTwo\E).*(?:\Q$nameOne\E))}; if ($text !~ $regex) { print "$name\n"; ++ct; }