in reply to dynamic hash name

It would be cleaner to use a hash-of-hash-type data structure, something like:
my %data; ... if ($type =~ /citystate/) { $data{citystate}{$key}; } elsif ($type =~ /citycountry/) { $data{citycountry}{$key}; } elsif ($type =~ /country/) { $data{country}{$key}; ...