in reply to Substitution with matching nested boundary conditions

This seems to do the trick:
$content =~ s{(foo.*?bar)}{ my $s = $1; $s =~ s{\Q$orig_zimzam\E}{$rep_zimzam}; $s; }sge;

Dave.