# ... snip opening the files ... my %file2data; while(<$input_file2>) { next if /(^\s*$)|(^#)|(^@)/; my @columns2 = split; $file2data{$columns2[0]} = $columns2[1]; } while(<$input_file1>) { next if /(^\s*$)|(^#)|(^@)/; my @columns1 = split; print $out_file join("\t", $columns1[0],$columns1[1], $file2data{$columns1[0]}), "\n"; }