What does $1 mean in Perl?

perl, regex

Solution

The `$number` variables contain the parts of the string that matched the capture groups `( ... )` in the pattern for your last regex match if the match was successful.

For example, take the following string:

$text = "the quick brown fox jumps over the lazy dog.";

After the statement

$text =~ m/ (b.+?) /;

`$1` equals the text "`brown`".

Problem

What does $1 mean in Perl? Further, what does $2 mean? How many $number variables are there?

Original source