What are you optimizing for?
Speed
Fix the algorithm.
Readability
Personally, I always recommend optimizing for readability first. Usually readable code is the kind of code that produces useful profiler stats. Which in turn helps you make things faster.
In this case you've really not said much. What do the data look like? How often do those regular expressions change? (and if they don't change you're barking up the wrong tree.) Are the 'logging' regexes the 'same' as those used in the main loop? If not, how similar are they?

Without facts, trying to optimize something is akin to answering the question "Can a piece of string be shortened?". The only possible answer is "Probably, yes." Optimization is, at least in part, the process of using the facts of a particular case to make the code 'fit' it better. Without good measurements all you get is off the peg code that fits where it touches.


In reply to Re: Precompiled Reg Exps by pdcawley
in thread Precompiled Reg Exps by jarich

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.