You are viewing the version of this documentation from Perl 5.41.7. This is a development version of Perl.
%{^CAPTURE_ALL}
%-

Similar to %+, this variable allows access to the named capture groups in the last successful match in the currently active dynamic scope. (See "Scoping Rules of Regex Variables"). To each capture group name found in the regular expression, it associates a reference to an array containing the list of values captured by all buffers with that name (should there be several of them), in the order where they appear.

Here's an example:

if ('1234' =~ /(?<A>1)(?<B>2)(?<A>3)(?<B>4)/) {
    foreach my $bufname (sort keys %-) {
        my $ary = $-{$bufname};
        foreach my $idx (0..$#$ary) {
            print "\$-{$bufname}[$idx] : ",
                  (defined($ary->[$idx])
                      ? "'$ary->[$idx]'"
                      : "undef"),
                  "\n";
        }
    }
}

would print out:

$-{A}[0] : '1'
$-{A}[1] : '3'
$-{B}[0] : '2'
$-{B}[1] : '4'

The keys of the %- hash correspond to all buffer names found in the regular expression.

The behaviour of %- is implemented via the Tie::Hash::NamedCapture module.

Note: %- and %+ are tied views into a common internal hash associated with the last successful regular expression. Therefore mixing iterative access to them via each may have unpredictable results. Likewise, if the last successful match changes, then the results may be surprising. See "Scoping Rules of Regex Variables".

This variable was added in Perl v5.10.0. The %{^CAPTURE_ALL} alias was added in 5.25.7.

This variable is read-only, and its value is dynamically scoped.