$ perl -wE '$r = q{bar$1}; $_ = "foo"; s/(fo)o/$r/e; say' bar$1