#!perl -w use strict; use IO::Socket; use IO::Select; my $server = IO::Socket::INET->new( Listen => 1, LocalAddr => 'localhost:8000' ) or die "socket failed: $!"; my $handles = IO::Select->new( $server ); # advantage: we know this is the first time $sessions # is being assigned to. Any '$sessions = ...' later in the # program are obviously replacing the contents of $session. my $sessions = {}; while ( my $socket = $server->accept() ) { $sessions->{$socket} = { peerhost => $socket->peerhost() }; }