For perls prior to 5.9.2 your regex is pretty well as good as it will get. Splitting it up as some folks suggest wont improve the situation IMO as the is an fixed string at the end that will have to be matched regardless. Actually there is a small problem there, you should $ or \z anchor the string on the right hand side or you might match a filename like "foo3.txt.bak" which probably isnt what you want.
With Perl 5.9.2 and later you will see better performance with
process_file ($_) if /(?:foo3|foo4|bar1|bar2)\.txt$/i;
Note the addition of the $ anchor and the removal of the /o modifier (which doesnt do anything for this regex anyway.)
In reply to Re: Regex Tuning /(?:(?:foo[34])|(?:bar[12]))\.txt/io
by demerphq
in thread Regex Tuning /(?:(?:foo[34])|(?:bar[12]))\.txt/io
by songahji
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |