my @sorted_data = sort { length $a <=> length $b || $count_hash{b} <=> $count_hash{$a} } keys %count_hash;