print "'hash{key}' is a hash reference\n" if ref(\%{$hash{key}}) eq 'HASH'; #### #!/usr/local/bin/perl5.6.0 use strict; use warnings; my $hash = { h1 => { ss1 => 'Howdy' }, h2 => { hh1 => { sss1 => 'Hello' } }, s1 => 'Doody', a1 => [], }; dig( $hash ); sub dig { my ( $hole ) = @_; if( ref($hole) eq 'HASH' ) { foreach my $l ( keys %{$_[0]} ) { dig( $_[0]->{$l} ); } } elsif ( ref($hole) eq 'ARRAY' ) { print q{What do I do with an Array ref?\n}; } else { my $leaf = $hole; # leaf in a hole?!? print qq{Found a leaf in an hole! [$leaf]\n}; } }