The funtionality you are talking about is implemented in
CPAN modules
CGI::Screen and
CGI::Application. Having never used them myself,
I cannot tell if they are an exact solution, but they are
probably worth looking at.
If you want to produce multiple pages in a single http responce, then you are talking
about http push, which can be done with CGI::Push, but is limited to netscape. Alternativly you can use a http pull through the Refresh http header, which is more widely supported but still relies on the clients.