# this bit is untested, 'tis bedtime for me open DATA, "$id_file" or die "something useful"; foreach $id sort ($b->[1] <=> $a->[1] } @results) { # read file until $_ (the ID) is found while () {next unless /^$id->[1]/} # If you want to use it later # $record_hash{$_)=+(split /your_sep/)[1] # or just print the record my $record=+(split /your_sep/)[1] print "$_->[0] \t $_->[1] \t $Record\n"; } # goodnight.