in reply to Make my script faster and more efficient

You're iterating over the keys of a hash where it appears exists would work.

while (<INPUT2>) { chomp; my ($bioC, $contig_id, $pip) = split /\t/; if ( exists $origins{ $contig_id } ) { print RESULTS "$bioC\t$origins{$contig_id}\t$pip\n"; } }

If, for some reason, you need to iterate over the keys on each line, you could save time by saving the result of sort keys in an array before looping over the lines.