# $hash_ref is passed in and defined outside # $key_to_find is what we want to find. # We will return the value of the first $key_to_find sub traverse_funky_hash { my ($hash_ref, $key_to_find) = @_; HASH_LOOP: foreach (sort keys %$hash_ref) { if ($_ eq $key_to_find) { return ($hash_ref->{$_}, 1); } next HASH_LOOP unless ref($hash_ref->{$_} eq 'HASH'); my ($val, $rc) = traverse_funky_hash($hash_ref->{$_}, $key_to_find); return ($val, $rc) if $rc; } return (undef, 0); }