To add to what
GrandFather said, have you considered trying this as a non-cgi problem and getting it to work that way first? Then when you see where and why it works, you can easily convert it to cgi. Also, you can use the Perl GUI debugger to watch your program's execution.
Revolution. Today, 3 O'Clock. Meet behind the monkey bars.
I would love to change the world, but they won't give me the source code