$text_to_search = \"example text with [foo] and more\"; $search_string = \"[foo]\"; if ($text_to_search =~ m/$search_string/) print \"wee\";
P
Use \Q to autoescape any potentially problematic characters in your variable.
\Q
if($text_to_search =~ m/\Q$search_string/) print "wee";