Please take the time to report the problem in its full form here. It's something you owe to the community.
Premature end of script headers can basically mean two things: that your script did not spit out anything, or that it printed something that cannot be considered an HTTP response.
You aren't telling us the whole story, anyway, because your code fragment starts with a comment about $data being already set up. Did you make sure that you actually reach that point? Are you sure your program isn't exiting before? Are you sure that you don't print anything on standard output before? What steps did you take to try and debug this?
Hey! Up to Dec 16, 2007 I was named frodo72, take note of the change! Flavio
Io ho capito... ma tu che hai detto?
perl -ple'$_=reverse' <<<ti.xittelop@oivalf