Thank you very much for all this, but I still don't get anything ("Premature end of data" from your code).
I'm ignorant - among other things :) - about sockets. I thought it could be something not depending from the Perl script istself but from something at "lower level" since the script works just the same on other older Linux computers. Also, on this new Linux computer the access to the same database with the same test query works with a php implementation, as I've just found out.