How to Circumvent Perl's string escaping the replacement string in s///? <p>I'm not sure what exactly to call this, but I've been able to reproduce my problem with two one-liners.</p> <p>Starting from a file 'test.txt' containing the following:</p> <pre><code>foo </code></pre> <p>After running the following command (in bash):</p> <pre><code>perl -n -e "s/(\w)oo/$1ar/; print;" test.txt </code></pre> <p>the output is '<code>far</code>'</p> <p>However, when I introduce a variable containing the replacement string, </p> <pre><code>perl -n -e '$bar = q($1ar); s/(\w)oo/$bar/; print;' test.txt </code></pre> <p>the output is '<code>$1ar</code>'.</p> <p>What do I need to change so that the second program will also output '<code>far</code>' and what keywords do I need to learn that would have made this answer Googleable?</p> <p>Also, I tried changing the second one to s///e, to no effect.</p> <p>Edit: This wasn't really the question I wanted to ask, which is <a href="http://stackoverflow.com/questions/4881345/how-to-circumvent-perls-string-escaping-the-replacement-string-in-s-when-its">here</a>.</p>