I don't have the time to try your code, but if line 16 is the one calling binmode $server; I bet it has to do with the fact that you don't check $server validity after the call to IO::Socket::INET->new.
As a general rule, always check that things dinamically set up are ok before using them.