Perl regex forward reference <p>I would like to match a forward reference with regexp. The pattern I am looking for is</p> <pre><code>[snake-case prefix]_[snake-case words] [same snake-case prefix]_number </code></pre> <p>For example: </p> <pre><code>foo_bar_eighty_twelve foo_bar_8012 </code></pre> <p>I cannot extract <code>foo_bar</code> and <code>eighty_twelve</code> without looking first at <code>foo_bar_8012</code>. Thus I need a forward reference, not a backward reference which work only if my prefix is not a snake-case prefix. </p> <pre><code>my $prefix = "foo"; local $_ = "${prefix}_thirty_two = ${prefix}_32"; # Backward reference that works with a prefix with no underscores { /(\w+)_(\w+) \s+ = \s+ \1_(\d+)/ix; print "Name: $2 \t Number: $3\n"; } # Wanted Forward reference that do not work :( { /\2_(\w+) \s+ = \s+ (\w+)_\d+/ix; print "Name: $1 \t Number: $2\n"; } </code></pre> <p>Unfortunately, my forward reference does not work and I do not know why. I've read that Perl support that kind of patterns. </p> <p>Any help ? </p>