use strict; use warnings; my @phrase = ( 'apple', 'apple', 'banana', 'banana', pear', 'pear', 'kiwi', 'kiwi' ); my %wordfreq; # Here $i contains the actual value from @phrase foreach my $i ( @phrase ) { $wordfreq{$i}++; print "$i appears ", $wordfreq{$i}, "\n"; }