Firstly, please put your code in code tags, like this:
[code]
#!/usr/bin/perl -w
use strict;
print "hello, world\n";
# etc.
[/code]
In that way, it will get displayed in a fixed-with font, like this:
Code:
#!/usr/bin/perl -w
use strict;
print "hello, world\n";
# etc.
Secondly, the error is in your mail log:
Code:
stat=Deferred: Connection timed out with gsmtp163.google.com.
For some reason, you couldn't reach gsmtp163.google.com in time. Try runnig ping $HOST, traceroute $HOST, tcptraceroute $HOST, host $HOST and netcat $HOST 25 (with $HOST=gsmtp163.google.com, or the proper entry into what I assume is a load-balancer).
If you know SMTP, try sending a message to yourself "manually" (netcat $HOST 25 might come in handy). Does the problem still happen? It might have been that google uses random load balancing and picked a crashed, hung or overloaded server for you.
Listen to the talk about debugging and sex therapy from LISA (
http://www.usenix.org/events/lisa04/tech/) if you've got the time. I really doubt it's sendmail's fault, but if nothing works try installing a different MTA or two.
Best of luck!