This is expected behaviour! It is obvious that you pattern will match, so it is no suprise that the corresponding if
-block is executed.
The term “backreferences” for $1, $2, ...
may be slightly suboptimal, let's call them “capture groups”.
In a regex, you can enclose parts of the pattern with parens to be remembered later:
/(silly)/
This pattern has one group. The contents of this group will be stored in $1
if it matches.
All capture group variables for groups that don't exists in the pattern or were not populated are set to undef
on an otherwise successfull match, so for above pattern $2, $3, ...
would all be undef
.