my $incoming = IO::Socket::INET->new( LocalPort => $MSGPORT, Proto => 'udp', Timeout => 1); ## some more code... while ( $incoming->recv( $msg, $MAX_SIZE ) ) { my ( $port, $addr ) = unpack_sockaddr_in( $incoming->peername ); push @messages, [ $addr, $msg ]; last if @messages > $MAX_INC_Q_SIZE; }