Yes. I forget how much difference that can make. Though joost's idea (with several modifications) works out fastest:

#! perl -slw use strict; use Data::Dump qw[ pp ]; use Benchmark qw[ cmpthese ]; our $string = join '|', map{ join rand() < 0.2 ? 'fred' : 'bill', 'pqr', 'xyz' } 1 .. 10000; our $first = 0; our %counts; cmpthese -1, { orig => q[ my @arr = split(/\|/, $string); my @arr1 = grep { /fred/ } @arr; $counts{ orig } = @arr1; ], Buk1 => q[ my @arr1 = grep { /fred/ } split /\|/, $string; $counts{ Buk1 } = @arr1; ], jwkrahn => q[ my @arr1 = grep /fred/, split /\|/, $string; $counts{ jwkrahn } = @arr1; ], Buk2 => q[ my @arr1 = $string =~ m[(?:^|\|)(.*?fred.*?)(?=\||$)]g; $counts{ Buk2 } = @arr1; ], JOOST => q[ my @arr1 = $string =~ /(?:^|\|)([^|]*?fred[^|]*?)(?=\||$)/g; $counts{ JOOST } = @arr1; ], }; pp \%counts; __END__ c:\test>junk6 Rate orig Buk1 JOOST jwkrahn Buk2 orig 20.2/s -- -28% -48% -58% -84% Buk1 28.1/s 39% -- -28% -42% -77% JOOST 39.2/s 94% 39% -- -19% -68% jwkrahn 48.4/s 140% 72% 24% -- -61% Buk2 124/s 515% 342% 217% 157% -- { Buk1 => 2010, Buk2 => 2010, JOOST => 2010, jwkrahn => 2010, orig => +2010 }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^3: Performance optimization question by BrowserUk
in thread Performance optimization question by vit

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.