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.*panel:(.*?):/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% --