my @array = qw( a a b c d d ); my %counts; my @keys = grep { !($counts{$_}++) } @array; print("$_: $counts{$_}\n") foreach @keys;