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