in reply to Return value from function

Returning references is fast, but making use of the reference later is not always very practical, as you now must write $r->{$key} where otherwise you could have written $r{$key}.

So often, I let the user decide, and base my return value on wantarray: If a sub is called in scalar context, I return a ref, but in list context, I return a flat list.

sub foo { my %hash = ( a => 1, b => 2 ); return wantarray ? %hash : \%hash; }
Call as either of:
my $hashref = foo();
or
my %hash = foo();