The Match object
You may have noticed, in the output from the previous examples, that the real substring is displayed between the pair of square corner brackets. This is because the content of the $0 and $1 variables is not a bare string but an object of the Match type. While printing using the say or print functions, the Match object is formatted in that manner.
Variables such as $0, $1, and so on, are in fact the shortcut variants of the full form—$/[0], $/[1], and so on. The $/ variable is the Match object. It is the default variable, which receives the result of the match with a regex. It contains all the captured strings, as well as the whole substring that matched with the whole regex. To get individual captures, indexes such as $/[1] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access