use IO::Select; # Do socket creation and checking... # Now play with IO::Select so we can wait three seconds for # a result. my $selector = IO::Select->new($sock); if ($selector->can_read(3)) { # 3 second timeout. # Do reading and checking stuff... } else { # Waited three seconds and couldn't read. Bummer. }