It's already been said, use a modular code organization. I would not use old style CGI. If you are stuck in a CGI type of environment, so called "modern" Perl web frameworks are a pain in the ass for this kind of constraint.
If you are transitioning from CGI to modernity, then I would recommend looking at CGI::Application. I still use it and it works well in many situations. However, it is not persistent. This shouldn't matter to you at this point.
CGI::Application encourages modularity and introduces you to a sane way to manage a request life cycle. Once you cut your teeth there, then you can look at the plethera of frameworks out there.