my %counts; while (<>) { $counts{ lc $_ }++ for split /\W+/; } print "$_: $counts{$_}\n" for sort keys %counts;