use strict; use IO::Socket; my $sock = new IO::Socket::INET (LocalHost => 'localhost', LocalPort => 5004, Proto => 'tcp', Listen => 5, Reuse => 1 ); die "Socket could not be created. Reason: $!" unless $sock; my ($new_sock, $buf); while ($new_sock = $sock->accept()) { print "Connection from ", $new_sock->peerhost, ": on port ", $new_sock->peerport,"\n"; print $new_sock "Hello from the server"; while (defined ($buf = <$new_sock>)) { print $buf; } } close ($sock);