perl -MO=Deparse -plwe "$h{$_}++ } for (sort {length($a) <=> length($b) } keys %h) {" BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } LINE: while (defined($_ = )) { chomp $_; ++$h{$_}; } foreach $_ (sort {length $a <=> length $b;} keys %h) { (); } continue { print $_; } #### while (<>) { your code here } continue { print $_ } #### perl -wlpe '}{*_=*.' filename