in reply to socket time out

Use IO::Select.
my $select=new IO::Select(); $select->add($connection); if ($select->can_read($timeout) { #handle timely answer } else { #timeout }