in reply to insert html tags

I will second moritz’s suggestion.   No matter what CPAN package(s) you use, you do want to use CPAN packages.   You want to parse the existing HTML into a data structure, modify that data structure, then generate the output HTML from that.

The problem that you will always have with “riding the pony bareback” is creating a successful, generalized solution that will work with every well-formed HTML document that you might throw at it (and, with those that are not).   A whole lot of CPAN implementors have lost hair-follicles building the answers to those questions, so that you might not have to lose so many of yours.