The text matched by the used group most-recently closed (i.e. the group with the rightmost closing parenthesis) of the last successful match. (See"Scoping Rules of Regex Variables").
This is subtly different from$+
. For example in
"ab" =~ /^((.)(.))$/
we have
$1,$^N have the value "ab"$2 has the value "a"$3,$+ have the value "b"
This is primarily used inside(?{...})
blocks for examining text recently matched. For example, to effectively capture text to a variable (in addition to$1
,$2
, etc.), replace(...)
with
(?:(...)(?{ $var = $^N }))
By setting and then using$var
in this way relieves you from having to worry about exactly which numbered set of parentheses they are.
This variable is read-only, and its value is dynamically scoped.
This variable was added in Perl v5.8.0.
Mnemonic: the (possibly) Nested parenthesis that most recently closed.
Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.
The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.