$foo = "bar baz"; { (local $foo = $foo) =~ s/bar/quux/; # do something with the modified $foo } # now the original $foo is back again