The easy way:
strip the code from the CGI into a function library, and require it from both the CGI and the command-line version. should be 3 minutes of effort.
The better way:
make a .pm of the functions, maybe even using the OO-style, and then just use it.
either way will work well.
Comment on Re: use the CGI.pm module only when script is used by a browser