use strict; use warnings; use IO::Socket (); my $listen_fh = IO::Socket->new( Domain => IO::Socket::AF_INET(), Proto => 'tcp', LocalAddr => '127.0.0.1', Listen => 1, ) or die("Unable to create listening socket: $!$/"); print('Listening on port ', $listen_fh->sockport(), '.', $/); my $client_fh = $listen_fh->accept() or die("Unable to accept a connection: $!$/"); print('Accepted a connection from ', $client_fh->peerhost(), ':', $client_fh->peerport(), '.', $/); while (<$client_fh>) { print $client_fh uc($_); } print('Connection closed by client or by error.', $/);