Take your existing code, and make the bulk of it into a function
definition. The function should take the 'string' as a parameter.
Once you've got that debugged, you can write code that reads your
pattern file, and for each line of it, calls the function you just
wrote.
You can certainly do it the way Peter describes, but if you learn to
factor each problem into separate functions (or classes, or generator,
or decorator, or ...) then your code will be easier to test, easier to
understand, and easier to reuse.
--
DaveA