my(@words, $count, $word); chomp(@words = ); foreach $word (@words) { $count{$word} += 1; #or $count{$word}++; } foreach $word (keys %count){ }