use IO::Socket::INET; use IO::Select; use strict; use warnings; my $socket = new IO::Socket::INET(Proto => "udp"); my $select = new IO::Select($socket); my $num_packet_rcvd; my $packet_rcvd; for (4000 .. 4100) {#change this to your logic of going thru peer list my $peer = sockaddr_in($_, inet_aton("localhost")); $socket->send("1234567890", 0, $peer) || die "send: $!";#instead of die, your real code shall handle it, for example logging print "packet sent to port $_\n"; } while (1) { my @sockets = $select->can_read(10); last if ($#sockets == -1);#no more reply within a reasonable amount fo time $num_packet_rcvd ++; $socket->recv($packet_rcvd, 100); print "rcvd packet $num_packet_rcvd [$packet_rcvd]\n";#you will replace this with your stuff }