for($m = 0; $m < scalar(@pathway_name); $m++) # foreach pathway name given by an integer { print "Pathway is $pathway_name[$m]\n"; # e.g.pathway name is 1 for($j = 0; $j < $rows; $j++) # for each row in my 2-D converted input file $file[][] { $n = 1; #print "Gene: $file[$j][0], Value: $file[$j][1]\n"; if($seen{$file[$j][0]}) # if the indexing element has already been seen { #print "Seen this Gene: $file[$j][0]\n"; # go on to the next row } elsif($file[$j][1]) # if the value exists { $n = 1; VALUE:while($file[$j][$n] =~ /\b\.+\b/gi) # while there is still a digit there (i.e. not a name { #print "Gene: $file[$j][0], Value:$file[$j][$n]\n"; #print "Entering if statement in while block...\n"; if($file[$j][$n] =~ /\b\Q$pathway_name[$m]\E\.\d+/) # if matches the combination of pathwayname.digit.digit { print OUTPUT "$file[$j][0]\t$pathway_name[$m]\n"; print "Gene: $file[$j][0], Value: $file[$j][$n] printed to output file\n"; #print "Going to last value.\n"; $seen{$file[$j][0]} = 1; # add the gene to the %seen hash for this pathway last VALUE; } else { #print "Gene: $file[$j][0], Value: $file[$j][$n] not matched.\n"; $n++; # go on to the next value } } # end while } # end elsif else { print "Skipped gene $file[$j][0]\n"; # go on to the next line } } # end while ($j < $row) undef %seen; # since going on to the next pathway, undefine %seen }