use strict; use warnings; my %h; while () { $h{$_}++ for map { lc } grep { /^[a-zA-Z]+$/ } split /\W+/; } for (sort keys %h) { printf "%10s %05d\n", $_, $h{$_}; } __DATA__ This line contains garbag3, and words! This line does not.