How are you doing it?
Perl lets you get into some bad habits with SQL connections.
Are you opening a new mysql connection for each statement, and then not closing them?
I use MySQL under TCL, and when I was starting out I used to have that problem. My trick is to open one connection, and the set a watchdog process to kill the connection after 5 minutes of inactivity, otherwise MySQL will kill it at some random interval, and depending on how smart your mysql client library is it may or may not screw up your program.
This watchdog maintains a flag that states whether the connection is live or not. My sqlstmt command checks the status of the flag and re-establishes the mysql link as needed.