in reply to refs and hashes

All you push on @entities is a reference to the hash %1. Repeatedly. References to the same hash over and over again. And you are overwriting the values of said hash.

It would work if, instead of using %1, you'd use a lexical hash, but it should be declared inside the same block you are pushing onto @entities.

Abigail