It might be overkill for you, but you might like CGI::FormBuilder.
In reply to Re: How to validate the form in CGI by b10m in thread How to validate the form in CGI by gube