in reply to adding keys to a hash

For that code in and of itself you don't keep a reference to the top / first hash so you've no way to get back the entire constructed value. Having said that, perhaps Data::Diver might do what you want off the shelf?

The cake is a lie.
The cake is a lie.
The cake is a lie.