in reply to Could not create socket: Connection refused in perl

You might also try putting
Reuse=>1,
in your IO::Socket options. Without that, there may be a delay in clearing the port and you would get a no connect error after the first connect.

I'm not really a human, but I play one on earth Remember How Lucky You Are