You could try setting socket option SO_KEEPALIVE using the sockopt method to IO::Socket. That might give you better notification when it breaks - although I can't say that I have tried it on PBX.
Thanks for your response but I believe the SO_KEEPALIVE works only if the server you are communicating with responds to a client which is not the case here. The PBX simple streams data as it happens via a port, it does not accept input nor respond to input on that port so I do not think this will work for me but please correct me if I am wrong!