#!/usr/local/bin/perl -n map {$h{lc($_)}++} split/\s/, $_; END { map { print "$h{$_}\t$_\n"} sort { $h{$b} <=> $h{$a} || $a cmp $b } keys %h }