I have opened the connection to the database prior to the subroutine shown here so that is not a problem.
I tried the other suggestions too i.e. the quoting and the $inserthandle->errstr suggestion but neither make any difference. By doing $inserthandle->execute or die $! I get the error connection reset by peer.