in reply to getting keys of multi-level hashrefs

Simple rule: if you have an (arbitrarily complex) variable that would print as HASH(0x...), surround it with %{ } and you can use that like any normal hash. Or add ->{key} after it, and you can access a value in it.

In your example the hash in $hash{$_} would be usable as a hash with %{$hash{$_}} and any value in it you could access with $hash{$_}->{key}. If that value is a reference again, just apply this rule again.