use strict; use warnings; use Data::Dumper; use v5.10; sub f {a=>1,b=>2} my %result = f(); #converts a a hash passed as an arry #back into a hash print Dumper \%result; print "to print just the keys of the hash:\n"; say "$_" for keys %result; # this is much faster, execution wise... # passes back a referecne to a hash that has # been already been created. sub x { my %result; $result{a}=1; #more likely way to set the results $result{b}=2; return \%result; } my $hash_ref = x(); print "to print the keys of this hash\n"; print "$_\n" for keys (%$hash_ref); print Dumper $hash_ref; __END__ $VAR1 = { 'b' => 2, 'a' => 1 }; to print just the keys of the hash: b a to print the keys of this hash a b $VAR1 = { 'a' => 1, 'b' => 2 };