if (exists $ref->{A}->{B}->{$key}) { } if (exists $hash{A}{B}{$key}) { } ...