perl -i.bak -nwe '$h{$_} = length; END { print sort { $h{$a} <=> $h{$b} } keys %h; }' \ file1 file2 ...