Problem with perl and fast cgi

I’m trying to convert a script from cgi to fast cgi using FCGI and CGI and following the general guidelines from the wiki. I’ve been able to create simple scripts based on the example, but when I try to convert my cgi script, I’m only able to run it about 5 times and then I get the http 500 incomplete headers error.

Each of the runs of the script runs slower and slower until about the 5th or 6th, then I get the 500 error and I can’t run the script any more. But, if I rename the script, I can run it 5 or 6 more times before it is disabled.

Is there anyway to enable more effective debugging of the script? It works fine from the command line and worked fine before it was converted to fast cgi.