my $listener = IO::Socket::INET->new( LocalPort => $port, Proto => 'tcp', Listen => 5, ReuseAddr => 1, ) or die "error: IO::Socket::INET: $@"; my $selector = IO::Select->new($listener); while ( my @ready = $selector->can_read() ) { for my $client (@ready) { if ( $client == $listener ) { my $new_conn = $listener->accept(); $selector->add($new_conn); my $fh_hex = sprintf '0x%x', $new_conn; print "Accepted new connection ($fh_hex)\n"; # ... sub recv_client { my $client = shift; my $fh_hex = sprintf '0x%x', $client; print "Recv from client ($fh_hex):\n"; # ... display data received ... } #### my $fh_hex = sprintf '0x%x', $new_conn; my $peerhost = $new_conn->peerhost(); my $peerport = $new_conn->peerport(); my $peeraddr = $new_conn->peeraddr(); my $peerhostfull = gethostbyaddr($peeraddr, AF_INET) || "Cannot resolve"; print "Accepted new connection $fh_hex ($peerhost:$peerport,host=$peerhostfull)\n";