$cn =~ /^(0|5|6)0+\Q$bn\E$
You never know with demerphq's future optimizations in regexp speed, but I'm quite sure that for now,
/^[056]0+/
will be faster than
/^(?:0|5|6)0+/

Benchmark code:

use Benchmark 'cmpthese'; my @list = ( '00012345', 'D123470', '0000123450', '0000023456', '50000 +123990' ); cmpthese -3, { charclass => sub { grep /^[056]0+/, @list }, alt => sub { grep /^(?:0|5|6)0+/, @list }, };

Benchmark result:

Benchmark: running alt, charclass, each for at least 3 CPU seconds... alt: 3 wallclock secs ( 3.00 usr + 0.00 sys = 3.00 CPU) @ 50 +5561.00/s (n=1516683) charclass: 3 wallclock secs ( 3.20 usr + 0.00 sys = 3.20 CPU) @ 53 +4972.53/s (n=1713517) Rate alt charclass alt 505561/s -- -5% charclass 534973/s 6% --

So it is indeed 5-6% faster, depending how you look at it.


In reply to Re: Merged list with regex matches by bart
in thread Merged list with regex matches by tcf03

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.