>perl -wMstrict -lne "/(\w+)/; $::i{$1}++; END { print qq{$_ $::i{$_}} for keys %::i } " words2.txt bar 2 baz 2 qux 2 foo 3