my $regex = ['(foo)',sub {\"bar$1"}]; my $string = 'blah foo blah'; $string =~ s/$regex->[0]/${$regex->[1]->()}/; print "S=$string\n";