sub walk_hash { my ($h1, $h2) = shift; foreach my $key (keys %$h) { # I presume you mean %$h1 here? if( ref $h->{$key}) { # And $h1->... here? walk_hash( $h->{$key} ); # and here? } else { print $h->{$key}; # and here as well? } } }