in reply to Re: Substituting without modifying
in thread Substituting without modifying

Your method works great using lexical variables as well, because the perl interpreter correctly interpolates the temporary value of $foo when that temporary value is in scope.
use strict; my $foo = "bar baz"; { (my $foo = $foo) =~ s/bar/quux/; # do something with the modified $foo $foo = "changed it"; print "The temporary value of foo is $foo.\n"; } # now the original $foo is back again print "The original value of foo is $foo.\n";
Running under ActiveState 5.6.1 and Windows ME, the above code first returns the temporary value of "changed it" and then the original value of "bar baz".