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