####################################################### # solution 1: ####################################################### print sort { length($b) <=> length($a) } <> ####################################################### # solution 2, which handles tabs by calling expand ####################################################### print sort { length($b) <=> length($a) } `expand @ARGV`; ####################################################### # solution 3, which handles tabs by doing it itself ####################################################### use English; for ( @lines = ) { while ( s/\t+/' 'x (length($MATCH) * 8 - length($RMATCH) % 8)/e ) { # spin spin spin } } print sort { length($b) <=> length($a) } @lines; ############################################################################ # solution 4, which handles tabs by doing it itself, keeping # the expanded version in a parallel array, then sorting by index, and # outputting the original values using the same sorted indices. ############################################################################ use English; while ( ) { push(@orig, $ARG); while ( s/\t+/' ' x (length($MATCH) * 8 - length($RMATCH) % 8)/e ) { # spin spin spin } push(@tabless, $ARG); } print @orig[ sort { length($tabless[$b]) <=> length($tabless[$a]) } 0 .. $#tabless];