#!perl -w die "usage: split \n" unless (@ARGV == 1); $file = shift; undef $/; open(FILE, "<$file") or die "can't open file '$file': $!\n"; while () { @words = split(/\s*,\s*/); foreach $word (@words) { $count{$word}++; } } close(FILE); foreach $word (sort mysort keys(%count)) { print "$word,\n"; } sub mysort { my($aa,$bb) = ($count{$a},$count{$b}); if ($aa == $bb) { return( $a cmp $b ); } else { return( $bb <=> $aa ); } }