Take the 2-minute tour × $text_to_search = "example text with
[foo] and more"; $search_string = "[foo]";  if($text_to_search
=~ m/$search_string/) print "wee";  Please observe above code.
For some reason I would like to find the text "[foo]" in the
$text_to_search variable and print "wee" if I find it. To do
this I would have to ensure that the [ and ] is substitued with
[ and ] to make perl treat it as characters instead of
operators.  Question: How can I do this without having to first
replace [ and ] with \[ and \] using a s/// expression?
share|improve this question I would say get into the habit of
using the qr// construct for regular expressions and escaping
special regex chars if literal is needed. Quotemeta will quote
ALL special regex chars. If you just want to find a literal
string in another, use index() instead. –  sln Jan 6 '11 at
17:01  3 Answers 3  Use the quotemeta function:  $search_string
= quotemeta "[foo]";  print "wee" if ($text_to_search =~
/$search_string/); share|improve this answer