In the IO::Socket.pm that I can look into, the code is like
sub connect {
@_ == 2 or croak 'usage: $sock->connect(NAME)';
my $sock = shift;
my $addr = shift;
my $timeout = ${*$sock}{'io_socket_timeout'};
my $err;
my $blocking;
$blocking = $sock->blocking(0) if $timeout;
if (!connect($sock, $addr)) {
so the call to connect should still be traceable a bit by single-stepping...Might help to know if the issue is before or after getting a local socket to use. Not that I think that would help too much, but it still might get you a bit closer to a solution.
Any chance to try the code on another machine ? Are you running this with the same privileges as when you do successfully telnet ? Maybe you can check if it behaves the same way when you run it as Administrator?