...............AAAAAAAA"ATGGCTC GTGTCCA"AAAAAAAAAAA ........... #### use Regex::PreSuf; sub superMatch { my ($patternFile, $dataFile, $outFile)=@_; open(PAT,"<$patternFile") or die "Can't open $patternFile, error $!"; my @patterns=; chomp @patterns; close(PAT); open(OUT, ">>$outFile") or die "Can't open output file $outFile, error $!"; # Regex::PreSuf generates a regex that will match all # of the patterns much more quickly than a naive # join "|",@patterns will my $re=presuf(@patterns); open(DATA,"<$dataFile") or die "Can't open $dataFile, error $!"; # NO NEED TO READ INTO MEMORY ALL AT ONCE! while() { # only compile regex once if(/$re/o) { # only chomp if we have a match chomp; # capturing matches are slower, so only capture # if one or more matches are present. # might have more than one match in a line! while(/($re)/og) { print OUT "'$1', '$_'"; } } } }