while(1){ while(sysread($sock, $content, 512)){ . . . #some stuff } $sock->close(); $sock = IO::Socket::INET->new (PeerAddr => 'localhost', PeerPort => '8902', Type => SOCK_STREAM, Proto => 'tcp', Reuse => 1, KeepAlive => 1, ); die "Could not create socket: $!\n" unless $sock; . . . }