in reply to subsitutuion operator

Maybe I'm barking up the wrong tree, but when I heard:

"...I am trying to go in and replace some of those lines via information generated in the program..."

the first thing that came to my mind was The Template Toolkit. I say this because I'm getting the impression that you're taking the output of your program and plugging values into a form (template!) with it.

Hope that helps.