You might want to take a look at Email::MIME::Kit, which takes a directory-based approach to constructing MIME mails. Using that approach, you could collect all the assets that make up a mail in a directory and change these assets.
On the other hand, now that I look at your source code, you seem to have more questions about how to use HTML::Template or maybe Template::Toolkit.
Maybe you can tell us what exact program you have, and where it does not do the things you want it to do. Please try to turn your program into a self-contained minimal example.