in reply to Whats quicker - passing along as variable to sub, or global var?

In some cases it makes sense to (mis)use for to create named aliases, which might improve readability, in particular if you need the variable several times in the routine.  This means you can use a self-explanatory variable name (as opposed to $_[0]).  And in contrast to using normal references, you don't have to mess with \$var and $$var (de)referencing syntax.

The following three variants are functionally equivalent in that they all avoid copying of the argument.

# named alias: sub func { # usage: func($string) for my $string ($_[0]) { $string =~ s/foo/bar/g; } } # direct @_ alias: sub func { # usage: func($string) $_[0] =~ s/foo/bar/g; } # explicit reference: sub func { # usage: func(\$string) my $stringref = $_[0]; $$stringref =~ s/foo/bar/g; }

And with large strings, all three variants are significantly faster than the "default" (copying) approach:

sub func { # usage: $string = func($string) my $string = $_[0]; $string =~ s/foo/bar/g; return $string; }