my $resultFile= "C://Users/kullaniciadi/Desktop/plasmodium/results.txt"; open (OUT, ">>$resultFile") or die ("Cannot open $resultFile"); open(geneREAD, $plasData) or die ("Cannot open $plasData"); my ($geneName, $line2, $epitope, $epiSeq, $locBeg, $locEnd); my $ctr; while($line2=) { $ctr=0; chomp($line2); if($line2=~ m/^Gene:\s*(.*)/) { $geneName= $1; if(grep(/^$geneName$/, @geneArr)) { while(substr($line2, 0 , 3) ne "---") { $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}})#call some values parsed earlier in the code from an array of hashes and compare them with locBeg & locEnd { if($locBeg <= $HoProPos{$snpID} && $HoProPos{$snpID} <= $locEnd) { if($ctr== 0)#this $ctr thing is used to print out gene's name only once in the output file {print OUT "Gene: $geneName\n";} print OUT "SNP $snpID found in epitope $epitope at protein position $HoProPos{$snpID}\n"; $ctr=1; } } } } } } }