Hi there.
I don't know almost anything about conf files, but I tought I could add one generic comment that MAYBE will help you.
Sorry if it doesn't.
Is there a pattern for a comment on them? Probably, right? So you could find a way to write a "simple" (the quotes are here because I can't tell the real complexity of your task) sub that ensures that anything matching that pattern would be preserved.
I know this sound pretty obvious, but sometimes we forgot the simple things - happens a lot to me.
Hope It helps you.
Best regards,
Er Galvão Abbott
a.k.a. Lobo, DaWolf
Webdeveloper