in reply to cleaner code ....

ikegami's right: that's about as clean as you'll get.

If you want to preserve order, I'd use a hash lookup to determine wether to add the elements instead of using unique; that should be a tiny bit faster but not as good looking. If you don't care about the order, ikegami's solution is better.

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