my @items = qw(foo poot bar foo baz poot foo); my %counts; ++$counts{$_} for @items; print "$_: $counts{$_}\n" for sort keys %counts;