in reply to Array of ($1, $2, ...) in replacement part of s///?

When you do a simple match, you can assign the captured portions to an array like this:

my $str = "foobarbaz"; my @a = $str =~ /(.)oo(.)ar(.)az/; local $, = ", "; print @a; __OUTPUT__ f, b, b

Given that, you can wrap the match in a qr// and run it twice:

my $regex = qr/(.)oo(.)ar(.)az/; my $str = "foobarbaz"; my @a = $str =~ $regex; $str =~ s/$regex/$3$2$1/; local $, = ", "; print $str, @a; __OUTPUT__ bbf, f, b, b

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated