in reply to Re: foreach (@array) s/x/y/ efficiency
in thread foreach (@array) s/x/y/ efficiency

To say that this made things extremely faster would be a complete understatement. After being blown away at first, I ran a pseudo-benchmark, and noted that it cut my run time (on that section of code only) by a factor of at least 14! Thank you!

Just for the sake of my personal education, here is what I came up with based on your suggestion. Did I get it right? Or is there an even better way?

foreach $phrase (@key_phrases) { my($worda,$wordb) = split(/ /, $phrase); my $pattern = qr/(\W|\b)($worda)(\W+)($wordb)(\W|\b)/; foreach (@material) { last if (s,$pattern,$1<U>$2</U>$3<U>$4</U>$5,i); } }

Thanks again for your help and wisdom, great one.

-Gryphon.