in reply to cleaner code ....

It looks clean to me.

uniq could be replaced with a hash if you don't care about order, but one could argue that would make it less clean.

for my $location (@locations) { next if $location eq 'HEADING'; my ($country, $state, $city) = split /,/, $location; ++$countries{$country}; ++$states{$state}; ++$cities{$city}; } @countries = keys %countries; @states = keys %states; @cities = keys %cities;