title: How do I perform a Perl substitution on a string while keeping the original?
body: <p>In Perl, what is a good way to perform a replacement on a string using a regular expression and store the value in a different variable, without changing the original?</p>
  
  <p>I usually just copy the string to a new variable then bind it to the <code>s///</code> regex that does the replacement on the new string, but I was wondering if there is a better way to do this?</p>
  
  <pre><code>$newstring = $oldstring;
  $newstring =~ s/foo/bar/g;
  </code></pre>