This doesn't much has to do with perl but with Apache’s configuration. You should check more on Apache side and play with the tunings or maybe use FastCGI.
There is also a module CGI::Inspect for debugging a running perl web application.
Re: output to STDERR/warn hangs Perl under Apache at ~64,800 bytes
Replies are listed 'Best First'.
Thanks for your input. Yes, this does seem to be more with Apache than Perl. For anyone else facing this issue, I found it does appear similar to a bug fixed back in Apache 2.0. where the stderr pipe fills up while Apache blocks awaiting stdout.
It does complete fine and flush stderr IF I close STDOUT, but that's hardly a good workaround.