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