sub safeCapture { # Workaround for Regex issue in which backtracked captures inside alternations inside repetition, will stomp on the capture value. my $prefix = shift; my $cap = shift; my $postfix = shift; return "$prefix($cap(?=$postfix))$postfix"; }