in reply to substitution problem with ()

The first argument of the substitution operator (s///) is a regexp, not arbitrary text. An easy way to convert arbitrary text into a regular expressions in to use quotemeta.

my $from_re = quotemeta($_); s/$from_re/$to/;

Replies are listed 'Best First'.
Re^2: substitution problem with ()
by bart (Canon) on Jun 12, 2007 at 17:01 UTC
    Or, in one go (and IMO simpler):
    s/\Q$from_re/$to/;

    "\Q$string" is the same as quotemeta($string), both in a doublequotish string and in a regexp.