my $haystack = 'lets test[1] this thing $string'; my @tests = ('test[1]', '\Etest[1]\Q', 'test\[1\]'); @tests = map {$_, qr"\Q$_\E"} @tests; print "Check $_:" . ($haystack =~ /($_)/ ? "got $1\n" : "no match\n") for @tests;