in reply to Changing a subroutine to a module

If you're using it in "many cgi scripts", yes, it does make sense putting it into a module; this way you'll prevent yourself from writing it over and over again.

As a plus, whenever you feel like changing your code, you'll only have to do it *once*, in the module.

How to do it... well, there's a lot to be said on the subject (I wrote a full article on this, but it hasn't been published yet). Use Module::Starter to start a module easily, check out the files it creates and post your questions here as they arise.