alarm_pg.pm: package pg_alarm; use strict; sub new { shift; my $seconds = shift; my $self = {}; $self->{CHILD_PID} = fork(); if ($self->{CHILD_PID} == 0) { sleep($seconds); } bless $self; return $self; } sub alarmed { my $self = shift; my $result = 0; if (defined($self->{CHILD_PID})) { my $ret = waitpid($self->{CHILD_PID}, 1); if ($ret == -1) { $result = 1; } } return $result; } 1; test.pl: use pg_alarm; use strict; my $a = pg_alarm->new(10); while (!$a->alarmed()) { #print "haven't gotten alarm yet\n"; } print "got alarm\n";