my $struct = {...}; # the hash of hashes in the question my $found; Data::Walk::walk \&wanted, $struct; print join(" ",sort keys %$found) ,"\n"; sub wanted{ if (/^values$/){ foreach ( keys %{$Data::Walk::container->{$_}} ){ $found->{$_}=1; } } }