Well you're doing a lot of work, searching though a large array for each entry in another large array.
but there are a few things you can try.
You don't need to extract the positions unless it's a line your interested in, so swap the order of those tests :-
foreach $line (@data) { if ( $line =~ /$one/ && $line =~ /$two/ ) { if ( $line =~ /(.*?)\s+(.*?)\s+(.*?)\s+(.*)+/ ) { $chr = $1; $pos1 = $2; $pos2 = $3; } ... } }
Try using index instead of a regex to match $one & $two, it's usually quicker.
if (index($line,$one) != -1 && index($line,$two) != -1) { ... }
Profile your code to find out where the time is going, and measure the difference each change makes.
In reply to Re: how to speed up pattern match between two files
by RichardK
in thread how to speed up pattern match between two files
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |