my $socket_resp = IO::Socket::INET->new(LocalPort => $response_port, Proto => 'udp', Blocking => 0, Timeout => undef); ... $received_data=&timeout_recv($socket,1024,10); ... sub timeout_recv { my $return; my $buf; my $cnt=0; for (1..$_[2]) { # $_[2] is timeout $_[0]->recv($buf,$_[1]-$cnt) // 0; # $_[1] is count of bytes to receive $cnt += length $buf; $return .= $buf; return $return if $cnt == $_[1]; sleep 1; # the ugliest line } die "Timed Out"; }