in reply to Re^2: Regex Substitution, Interpolating on the RHS?
in thread Regex Substitution, Interpolating on the RHS?

Yes, you would check ref($regex->[1]). It will be 'CODE' for a coderef and false (empty) for a non-ref. You could put the whole test/selection into the block like so:
my $regex = ['(foo)',sub {\"bar$1"}]; my $string = 'blah foo blah'; $string =~ s/$regex->[0]/${(ref($regex->[1]) eq 'CODE' ? $regex->[1]-> +() : \$regex->[1])}/; print "S=$string\n";

Caution: Contents may have been coded under pressure.