open INDAT, "file1" or die "$!"; my @array; my @probes; open INCOMP, "file2" or die "$!"; while (){ @array=split/\t/; while (){ chomp ( $_ ); @probes=split/\t/; if ($array[0]=~/$probes[1]/i){ print $probes[1];#or whatever else } } seek INCOMP, 0 , 0; } close INCOMP;