in reply to Regex substitution problem

In the replacement field of a substitution, the capture variable  $1 and not the backreference  \1 should be used.  use warnings; would have suggested this.

Also, it is not clear if the text you give in your post is multi-line, i.e., if it has embedded newlines, or if it is a single string (which seems most likely). In the former case, use a /s regex modifier (see perlre section Modifiers) which allows the  . (dot) metacharacter to match newlines.