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";