Counting the opening parentheses to get the correct number for a backreference is error-prone as soon as there is more than one capturing group.
A more convenient technique became available with Perl 5.10: relative backreferences.
To refer to the immediately preceding capture group one now may write \g{-1} , the next but last is available via \g{-2} , and so on.
Another good reason in addition to readability and maintainability for using relative backreferences
is illustrated by the following example, where a simple pattern for matching peculiar strings is used:
$a99a = '([a-z])(\d)\g2\g1'; # matches a11a, g22g, x33x, etc.
Now that we have this pattern stored as a handy string, we might feel tempted to use it as a part of some other pattern: