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

perlfaq6:

In versions 5.6 and later, Perl won't recompile the regular expression if the variable hasn't changed, so you probably don't need the /o option. It doesn't hurt, but it doesn't help either.

perlop:

... the largely obsolete /o ...
The bottom line is that using /o is almost never a good idea.

Then what about something like benchmark below (this is 5.42, and I _do_ see a small but noticeable performance bump with real code which does some heavy lifting when parsing. I don't think any variables have changed; just wanted to split pieces of a regex into separate variables for clarity):

use strict; use warnings; use feature 'say'; use Benchmark 'cmpthese'; my $pat = qr/\d+/; my $s = '123abc' x 1e6; cmpthese -1, { foo => sub { 1 while $s =~ /\G $pat \D+ /cgx }, bar => sub { 1 while $s =~ /\G $pat \D+ /cgxo }, }; __END__ Rate foo bar foo 1213522/s -- -88% bar 10345112/s 752% --

Replies are listed 'Best First'.
Re: Are perlfaq6 and perlop correct about "/o" modifier?
by choroba (Cardinal) on May 09, 2026 at 13:14 UTC

      (Oops, shouldn't have used "/c" in benchmark, and should have noticed unrealistic results for such a long input. I'm sorry. Copied "/cg" and "\G" from RL code, thought maybe it's relevant for how "/o" behaves. The premise in the title is still the same.)

      Thanks for the link, that's scary. Perhaps I'd better not "split" a regex into smaller chunks, let it stay long.