Is it possible to make a "search and replace" work where the replacement is a variable containing $1, $2, ... special variables?
#!/usr/bin/env perl
use strict;
use warnings;
use 5.10.0;
my $row = 'ab';
my $pattern = '^(.)(.)';
my $replacement = '$2-$1';
$row =~ s/$pattern/$replacement/;
say $row; # $2-$1
Use String::Substitution's
sub_modify.Notes:
gsubinstead ofsubif you want the behaviour of thegmodifier.copyinstead ofmodifyif you want the behaviour of thermodifier.