my @array = ('foo', 'foo', 'bar', 'foo', 'bar', 'baz'); my %count; $count{$_}++ for @array; for(sort(keys(%count))) { print "$_: $count{$_}\n"; }