in reply to Regex help

quotemeta is the best way to do this

If u want to this by the explicitly instead of using the quatemeta just add the character you want to prefix with the "\" in the substitute.

while(<>){ $_=~ s/([\$|\||\[|\)|\\|\/|\(])/\\$1/g; print; }
Vinoth,G

Replies are listed 'Best First'.
Re^2: Regex help
by bingohighway (Acolyte) on May 06, 2009 at 13:34 UTC
    How about reading a string, searching for the regex (i.e. encased by /$regex/) and only doing this substitution within the regex delimeters? Cheers!