$text_to_search = \"example text with [foo] and more\"; $search_string = \"[foo]\"; if ($text_to_search =~ m/$search_string/) print \"wee\";
P
Use the quotemeta function:
$text_to_search = "example text with [foo] and more"; $search_string = quotemeta "[foo]"; print "wee" if ($text_to_search =~ /$search_string/);