#!/usr/bin/perl use strict; use warnings; use IO::Socket; sub makeSock { my $socket = new IO::Socket::INET( PeerAddr => 'localhost', PeerPort => 7070, Proto => 'tcp', ); die "Could not connect\n" unless $socket; return $socket; } my $i = 1; while( 1 ) { my $socket = makeSock(); print $socket $i; close( $socket ); $i++; }