in reply to perl string pass by value

Perl always passes by reference (not by value), so calling a sub doesn't copy the arguments.

However, the standard practice is to copy the arguments into local variables (e.g. my ($x, $y) = @_;), effectively getting copy-by-value semantics.

Since 5.20, Perl uses a copy-on-write mechanism that avoids actually copying the string until required (by the string being modified), so that copy is cheap.

sub foo { my ($s) = @_; # String copied here before 5.20 $s =~ s/.//s; # String copied here since 5.20 } foo($str); # No copying here.

So,