What's supposed to happen when "zimzam" occurs more than once within a given "foo ... bar" span? Note that the excellent solution provided by dave_the_m would only replace the first occurrence in that case, but just add a "g" modifier on the "inner" s/// operation to make it apply to all occurrences of "zimzam" within the captured "foo...bar" range.