It looks to me like you need to either preserve the original sentence and run a global substitution on it once for the sentence #1 output, and then run again with a non-global substitution for each of the other sentences, addressing each match one at a time; or else put a function in the replacement side of the substitution and do your processing within that function.