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