use IO::Socket; use IO::Select; my $port1 = 80; my $port2 = 81; my $sock1 = new IO::Socket::INET(Port => $port1, Proto => 'tcp', Listen => 1, Reuse => 1, Timeout => 60); die "can't open $port1 ($!)" unless $sock1; my $sock2 = new IO::Socket::INET(Port => $port2, Proto => 'tcp', Listen => 1, Reuse => 1, Timeout => 60); die "can't open $port2 ($!)" unless $sock1; my $sel = new IO::Select; $sel->add($sock1); $sel->add($sock2); while(1) { my @handles = $sel->can_read(10); # timeout after 10 secs foreach my $h (@handles) { if($h == $sock1) { # do something with port 80 data } elsif($h == $sock2) { # do something with port 81 data } } }