Your problem would appear to be that you're testing the hash for being empty, c/w a test for the existence of an individual key on the hash i.e. change unless (! %seen) to unless (! %seen->{$hosts->name}), or some such...
A user level that continues to overstate my experience :-))