You can get really complex with this (using templates, and OO Perl) which is great but you have a learning curve ahead of you. So, since you are pretty new I suggest this:
This is quick and dirty and is fairly easy to implement. But, keep in mind it is quick and dirty. Where something like this gets out of hand is when you have a bunch of these sort of scripts scattered throughout your site. Don't do that :)