Nginx giving error when trying to process CDR in XML format

Hi guys.
I am battling to get my perl script to process the XML cdr record from Freeswitch. I have the exact same config that I have on an older version, and the older version works perfectly.
Nginx gives the error “upstream prematurely closed FastCGI stdout while reading response header from upstream” , and then sends a error 502 to Freeswitch.

I have tested nginx , and it responds to a simple cgi_test.pl script perfectly.

My code is based on fs-xml-cdr.pl which is found on

Any suggestions will be appreciated.

thanks in advance
Clive