http://www.perlmonks.org?node_id=810415


in reply to Re^4: Speeding up named capture buffer access
in thread Speeding up named capture buffer access

If the optimisation is that important, couldn't you just ‘pre-compile’ by doing the counting (laboriously and by hand, if necessary) once and taking into account the various possibilities? It's less elegant, but it seems that speed rather than elegance is your primary driver (with elegance a secondary bonus).
$re = qr/(?<h1>...)(?<m1>...)(?<s1>...)|(?<h2>...)(?<m2>...)(?<s2>...) +/; $string =~ $re; ( $h, $m, $s ) = ( $1 || $4, $2 || $5, $3 || $6 );