while () { #add the name, mass, rt(time) and type to an array chomp $_; my @columns = split (/\t/, $_); my $keyname = $columns[0]; my $keymass = $columns[1]; my $keytime = $columns[2]; my $keytype = $columns[3]; my $key = "$keymass"."\t"."$keytime"."\t"."$keyname"."\t"."$keytype"."\n"; # Mass (to allow range for user to search based on tolerance they input) $masst1 = $keymass + $masstoleranceinput; $masst2 = $keymass - $masstoleranceinput; for ($keymass) { for ($keytime) { if (defined ($keytime) && defined ($rtinput)) #skip those with blank cells at "Time" column { #allow user to choose time range based on tolerance they set $rt1 = $keytime + $rttoleranceinput; $rt2 = $keytime - $rttoleranceinput; #match according to mass and time against library if (( $masst2 <= $massinput && $massinput <= $masst1 ) && ( $rt2 <= $rtinput && $rtinput <= $rt1 )) { print OUT1 "$massinput\t$rtinput\t\t$key"; } } else #for those cells at "Time" column that is left blank, go to this loop where only mass is being matched { #match against mass only if (( $masst2 <= $massinput && $massinput <= $masst1 )) { print OUT1 "$massinput\t$rtinput\t\t$key"; } } } } } #### _LIBRARYDATA_ Name Mass Time Type John 223.41 1.20 Boy Betty 111.23 Girl Ken 100.25 0.56 Boy . . . _INPUTDATA_ e.g. Mass Time 100.20 0.55 150.34 0.23 223.45 1.22 223.44