sub foo { return length($_[0]); } #### sub dot_to_underscore { $_[0] =~ s/\./_/g; } my $string = 'hello.world'; print "$string\n"; dot_to_underscore($string); print "$string\n"; #### sub dot_to_underscore { my $string = $_[0]; # No copy on 5.20+, but yes, copy under <5.20. $string =~ s/\./_/; # Copy made under 5.20 because of copy-on-write. return $string; # No copy under 5.20+ until the *caller* modifies the return string. But yes, the caller will get a copy pre-5.20. }