When you make the test
if ( exists $test_hash{$key1}{$key2} ) {
print "The double key exists\n" ;
}
you're not testing for whether a value exists for the two-part key
$key1, $key2. Rather, you're testing for the existence of the key
$key2 within the hash
%test_hash{$key1}. The existence test implicitly creates the empty hash.
Should that be the way exists works? Good question. "Does this key exists in this hash?" is a subtley different question than "Does this hash exist, and does this key exist within it"? I'm not sure that extending exists to answer the latter is a good thing, given that means exist to answer the questions independently.