There are many templating solutions out there that you can find. The best thought-through in the Perl world is probably the [link|http://template-toolkit.org/|Template Toolkit]. Whether or not you want to use Perl, or that particular templating tool, you owe it to yourself to read their article [link|http://template-toolkit.org/tpc4/index.html|Building and Managing Websites with the Template Toolkit].

If you have existing pages and you want to make a fixed edit to all of them at once, I would suggest writing a script, making a copy of your pages, and running the script against them. Check the output, if it is wrong then edit the script and try again. This usually can be made to work with less effort than hand-editing, but it is not, a permanent solution.

Cheers,
Ben