in reply to Re: Replace part of a regex match
in thread Replace part of a regex match

I might also offer the suggestion that the regexp you've chosen is hard work for Perl. It means capture as much as possible, and only then check if a pipe symbol comes afterwards. That there are several of these ensures that this regexp isn't that efficient.

You might like to try something like the following:

my $re = qr/ (?: # start non-capturing group [^\|]+ # as many non-pipe characters as possible \| # followed by a pipe character ){5} # and ensure there are 5 such groups in a row ([^\|]+) # capture as many non-pipe chars as possible /x;

Using Benchmark the new regular expression here was 400% faster on my computer:

Rate oldway newway oldway 108225/s -- -81% newway 563910/s 421% --

Update: corrected URL