It worked when I put while(<FH>) and kept working when I forced the while condition to be true.
Thanks for the correction on directly using the $oSocket.
The same code accessing the same SQL server has a different behavior on different Linux boxes.. I hope this fix will work on the old ones :)