sub is_hash { my($hash, @keys) = @_; return unless defined $hash && ref($hash) eq 'HASH'; return $hash unless @keys; my $yes; for (@keys) { $yes = undef, last unless ref $hash eq 'HASH' && %{ $hash }; $yes = undef, last unless exists $hash->{$_} && defined $hash->{$_}; $yes = 1; $hash = $hash->{$_}; } return $yes ? $hash : $yes; }