There must be something unusual about OP's data. A simple test gives very similar results for the two techniques:
use warnings; use strict; use Benchmark qw(cmpthese); my $target = 'Some leading text' . 'chrMatchTextForChr ' . 'Some text to be ignored following chr ' . 'urn:lsid:UrnLisdMatchText ' . 'Text to be ignored after urn:lsid match text' . 'panel:Text: Some text that doesn\'t get matched by anything'; die "Different results" if all () ne parts (); cmpthese (-1, {'all' => \&all, 'parts' => \&parts}); sub all { my ($chr,$prot,$panel) = $target =~ /(chr.*?)\s.*urn:lsid:(.*?)\s.*pan +el:(.*?):/i; return "$chr$prot$panel"; } sub parts { my ($chr) = $target =~ /(chr.*?)\s/i; my ($prot) = $target =~ /urn:lsid:(.*?)\s/i; my ($panel) = $target =~ /panel:(.*?):/i; return "$chr$prot$panel"; } Prints: Rate parts all parts 82116/s -- -17% all 98443/s 20% --
In reply to Re: Regex, capturing variables vs. speed
by GrandFather
in thread Regex, capturing variables vs. speed
by albert
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |