Often there are other considerations. For instance, if you were doing the s/// on dashes preceeded and followed by digits, what you expect from "1-2-3" would dictate which to use.

The speed difference is not due so much to capturing or not but to the fact that substituting a constant string (with /g) loops inside the subst opcode, while interpolating a variable builds a loop of other opcodes, just as if you had s///e:

$ perl -MO=Concise,-exec -we's/(?<=\d)-(?=[A-Z])//ig' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v 3 <$> const[PV ""] s 4 </> subst(/"(?<=\\d)-(?=[A-Z])"/) vK 5 <@> leave[1 ref] vKP/REFC -e syntax OK $ perl -MO=Concise,-exec -we's/(\d)-([A-Z])/$1$2/ig' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v 3 </> subst(/"(\\d)-([A-Z])"/ replstart->4) v 4 <#> gvsv[*1] s 5 <#> gvsv[*2] s 6 <2> concat[t3] sK/2 7 <|> substcont(other->3) sK/1 8 <@> leave[1 ref] vKP/REFC -e syntax OK
But even so, remember that optimization should be one of the last steps in development. Write the code however is most clear to you; then, only if there is a performance problem, do some profiling and optimization. (But if either way is equally clear and equally easy, obviously go with whichever you think may be faster.)

In reply to Re: lookahead / lookbehind vs other regex methods by ysth
in thread lookahead / lookbehind vs other regex methods by shemp

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.