Using your code as a specification, rewrite it using CGI::Application, DBIx::Class (or Class::DBI), and Template Toolkit. While there's a learning curve on each of those distributions, you will thank yourself in the morning.
My criteria for good software:
Does it work?
Can someone else come in, make a change, and be reasonably certain no bugs were introduced?