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:
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.)$ 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
In reply to Re: lookahead / lookbehind vs other regex methods
by ysth
in thread lookahead / lookbehind vs other regex methods
by shemp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |