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