use strict; use warnings; my %scGeneids; # gene ids for marker genes my $key; open(INlist,"scCOGwSNPs_geneids.txt"); while(){ chomp; $scGeneids{$_}=1; } close(INlist); open(IN,"snps.position.txt") or die "can't open infile"; open(OUT,">markerGen_allSNPPos.txt"); foreach $key (keys %scGeneids){ print "searching for $key \n"; while (){ chomp; my @columns=split("\t",$_); my $gene_id=$columns[0]; my $SNP_pos=$columns[2]; if ($key eq $gene_id){ print OUT join("\t",$key,$SNP_pos),"\n"; } } } close(IN);