my %count; my @ulist = sort { ($count{ $b } ||= TabCount( $b ) ) <=> ($count{ $a } ||= TabCount( $a ) ) } values %unk; sub TabCount { $_ = shift; s/\s+$//; my @split = split /\t/; return $#split; }