http://www.perlmonks.org?node_id=993227


in reply to Extracting values from nested hashrefs

Using recursion:
use 5.010; my $animals = { gnu => { humps => 0, mascot_for => 'emacs', }, dromedary => { humps => 1, zzz => { humps => 'nested', aaa => { humps => 'really nested', xxx => 0, }, }, mascot_for => 'perl', }, }; sub print_humps { my $hash_ref = shift; foreach my $key (keys %{$hash_ref}) { if (ref $hash_ref->{$key} eq "HASH") { print_humps($hash_ref->{$key}); } elsif ($key eq 'humps') { say $hash_ref->{$key}; } } } print_humps($animals); __END__ 0 1 nested really nested