perl -plwe'$h{$_}++ } for (sort { length($a)<=>length($b) } keys %h) {' infile >infile.tmp