If I understand correctly, calling if (exists $ref->{A}->{B}->{$key}) { ... } will spring into existence $ref->{A} and $ref->
if (exists $ref->{A}->{B}->{$key}) { ... }
$ref->{A}
$ref->
Check every level for existence before looking at the top level.
exist
if (exists $ref->{A} and exists $ref->{A}{B} and exists $ref->{A}{B}{$key}) { }
If you find that annoying you could always look on CPAN. For instance, there is Hash::NoVivify.