my @array = qw( a a b c d d ); my %counts; $counts{$_}++ for @array; # if you really want arrays back at the end: my @keys = keys %counts; my @vals = values %counts;