my @sorted_col_names = sort { length($a) <=> length($b) || $a cmp $b } keys %$cols; foreach my $col_name (@sorted_col_names) { my $cell = $col->{$col_name}; print("$cell\t"); } print("\n");