http://www.perlmonks.org?node_id=128838


in reply to Escape from backslash hell

all of my attempts thus far have failed to produce the desired result, all return either the original string or 11\\/29\\/2001.
I wonder if you're checking the results in the debugger... Be aware that if you examine the contents of a variable (with x, X, or V), the debugger will escape quotes and backslashes, in order to produce a valid quoted string. However, if you print the contents of a variable (with p or print), you get just the contents.

Here's an example, showing that your second attempt works, although the debugger's output might be a bit misleading:

DB<1> $_ = "2001/11/30" DB<2> s{/}{\\/}g DB<3> x $_ 0 '2001\\/11\\/30' DB<4> p $_ 2001\/11\/30 DB<5>