# initialize your IO::Socket etc... $SIG{ALRM} = sub { # code here to do something interesting # if your program isn't getting # connections } my $minutes_to_wait = 5; # wait five minutes my $alarm_seconds = $minutes_to_wait * 60; alarm $alarm_seconds; # set the first alarm while($server->recv($msg,$MAX_LEN) { # if we're here we got something # do some interesting stuff with the message #reset the alarm alarm $alarm_seconds; }