my $ctr; while($line2=) { $ctr=0; chomp($line2); if($line2=~ m/^Gene:\s*(.*)/) { $geneName= $1; #print "$geneName\n"; if(grep(/^$geneName$/, @geneArr)) { while(substr($line2, 0 , 3) ne "---") { #print "$line2\n"; $line2=; chomp($line2); if($line2=~ m/(\d*)\s*([A-Z]*)\s*(\d*)-(\d*)/) { $epitope= $1; $epiSeq= $2; $locBeg=$3; $locEnd=$4; foreach $snpID(@ {$snpHash{$geneName}}) { #print "$snpID $HoProPos{$snpID}\n"; if($locBeg <= $HoProPos{$snpID} && $HoProPos{$snpID} <= $locEnd) { if($ctr== 0) {print OUT "Gene: $geneName\n";} print OUT "SNP $snpID found in epitope $epitope at protein position $HoProPos{$snpID}\n"; $ctr=1; } } #print "$1 $2 $3 $4\n" } } } } }