You are locking for is Apache::PageKit
where your content, code and view is seperated (MVC). It works perfect with most databases and it has a easy example shipped with the source. You have to look at the example source Apache-Pagekit-1.12/eg/ while browsing to the examplesite somewhere at pagekit.org. To hear the ahhh's and ohh's.