If it's a stand-alone cgi you can run it on the command line or with the perl debugger and step through it until you find where it hangs (see perldoc perldebug).
If you are running inside mod_perl you can still use the debugger quite simple - take a look at Apache::DB