my $index = 'path/to/file/file.name'; tie (@master, 'Tie::File', $masterList) or die "Can't tie $masterList"; foreach my $pos(@master){ chomp $pos; my $quickLook = qx(grep '^$pos' $index); my @split = split(/\t/,$quickLook); print $tFile $split[1]; push (@idxArray, $split[1]); } #### 1 2 3 4 6 8 10 12 15 17 etc... 3000000 #### 1 atc 2 gca 3 att 4 ggc 5 aaa etc... 29000000 ttg