use Scalar::Util qw(reftype); my $reftype = reftype $hash{test}{1}; defined $reftype and $reftype eq "HASH" ? ...