You are looking at the documentation for Perl 5.14. This example does not appear in the documentation for Perl 5.12 .
You can see that it is marked as a new feature in perl 5.13.2 delta .
You can copy a variable and then modify it to achieve the same effect in older versions of Perl.
$x = "I like dogs."; $y = $x; $y =~ s/dogs/cats/; print "$x $y\n";
Or you can use the idiomatic "single line":
$x = "I like dogs."; ($y = $x) =~ s/dogs/cats/; print "$x $y\n";
Quentin
source share