use warnings; use strict; chomp(my @data_array=); print join $/ => map{$_->[0]} sort{$a->[1] <=> $b->[1]} map{[$_,(split/\s+/,$_,2)[1]]} @data_array; __DATA__ AA 34 AB 22 AC 12 #### AC 12 AB 22 AA 34 #### my %hash; while(){ next if /^\s*$/; my @data = split; $hash{$data[1]} = $data[0] } print $hash{$_},' ',$_,$/ for sort{$a<=>$b} keys %hash; __DATA__ AA 34 AB 22 AC 12