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.)

---
demerphq


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.