in reply to Change this example to use references...

I hate to say it, but in this case using a subroutine is overkill. You can wipe out sub eval_array_size and change the two lines that call it to this:
print scalar @var, "\n";
But back to your question. Let's use another example:
#!/usr/bin/perl -w use strict; use Benchmark; timethese(100, { 'no ref' => sub { my @array = sub1() }, 'ref' => sub { my $arref = sub2() }, }); sub sub1 { my @arry = (0..100000); return @arry; } sub sub2 { my @arry = (0..100000); return \@arry; }
and the results:
Benchmark: timing 100 iterations of no ref, ref... no ref: 33 wallclock secs (28.19 usr + 0.07 sys = 28.26 CPU) @ 3.54 +/s (n=100) ref: 10 wallclock secs ( 9.21 usr + 0.34 sys = 9.55 CPU) @ 10.47 +/s (n=100)
Passing arrays/hashes/objects/data structures around in Perl is much more efficient when you pass them as references, but it can get you into trouble if you aren't careful:
sub new { my $class = shift; my $self = { list => { a => 'ls', b => 'pwd', c => 'date', }, }; bless $self, $class; return $self; } sub get_list { my ($self) = @_; return $self->{'list'}; }
This object has an attribute called list, it is simply a hash reference with some key value pairs. If a client gets a copy of the list via get_list(), that client can modify the contents of the list. Not good. get_list() would be better as:
sub get_list { my ($self) = @_; my %ref = %{ $self->{'list'} }; return \%ref; }
Now, even though get_list returns a reference, it is not a reference to the original list, instead it is a reference to a copy of the original list.

Hope this helps, references are tricky to explain. I always try to explain them by asking the asker "what does a variable really hold?" It's not a value, a variable holds the memory location where a value is stored. Therefore, a variable can hold the memory location of a value that contains another memory location of the actual value . . . and so on . . .

perl -le '$x="jeff";$x++ for(0..4482550);print $x'