$text =~ s/\s+|(STARTPRESERVE(\d?).*?STOPPRESERVE$1)/${[$1,' ']}[!$1]/gs;