http://qs321.pair.com?node_id=792168

casiano has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

The /p modifier introduced in 5.10 makes ${^PREMATCH}, {$^MATCH}, and ${^POSTMATCH} available for use after matching. It is assumed it is faster than using $`, $& and $'. But when I benchmark this code:

pl@nereida:~/src/perl/perltesting$ cat ./timeregexpwithp.pl #!/usr/local/lib/perl/5.10.1/bin//perl5.10.1 -w use strict; use Benchmark qw{:all}; cmpthese( 1000000, { p => q{'hola juan' =~ /ju/p; my ($a, $b, $c) = (${^PREMATCH}, ${^M +ATCH}, ${^POSTMATCH} ) }, oldway => q{'hola juan' =~ /ju/; my ($a, $b, $c) = ($`, $&, $') } } ); cmpthese( 10000000, { pnoassign => q{'hola juan' =~ /ju/p; }, oldwaynoassign => q{'hola juan' =~ /ju/; } } );
I've got:
pl@nereida:~/src/perl/perltesting$ ./timeregexpwithp.pl Rate p oldway p 892857/s -- -6% oldway 952381/s 7% -- Rate oldwaynoassign pnoassign oldwaynoassign 3184713/s -- -1% pnoassign 3225806/s 1% --
It seems that the old way is faster. Any explanations?

Thanks