my $x = \" VERY VERY BIG STRING ....."; my $len = length( $$x ); #### my $string = 'Long string' x 100000; sub psau() { print grep { /\b$$\b/ } `ps au` } # POSIX platforms sub bar { psau } sub foo { my $s = shift; psau } sub mod { my $s = shift; $s =~ s/Long/LONG/g; psau } psau; bar($string); foo($string); mod($string); psau; #### use Devel::Size qw< size total_size >; sub size_print($\$) { my ($name, $ref) = @_; printf "%20s %5d %5d\n", $name, size($ref), total_size($ref); } my $string = 'Long string' x 100; printf "%20s %5s %s\n", qw; size_print '$string', $string; my $collection = [ ]; size_print '$collection (empty)', $collection; push @$collection, \$string; size_print '$collection ( one )', $collection; push @$collection, \$string; size_print '$collection ( two )', $collection; __END__ Name size total_size $string 1134 1134 $collection (empty) 24 88 $collection ( one ) 24 1278 $collection ( two ) 24 1302 #### use Benchmark qw; my $string = 'Long string' x 1000; my $really_long = $string x 100; my $ref = \$string; my $long_ref = \$really_long; cmpthese(-5, { map { $_ => "length($_)" } qw< $string $$ref $really_long $$long_ref > }); __END__ Rate $$long_ref $$ref $really_long $string $$long_ref 17305170/s -- -9% -36% -38% $$ref 18937129/s 9% -- -30% -32% $really_long 27185304/s 57% 44% -- -2% $string 27870647/s 61% 47% 3% --