#!/usr/bin/perl use warnings; sub after { my ($time, $anonsub) = @_; do { $id = int(rand(10000)); } while (defined($times{$id})); $times{$id} = $time; $subs{$id} = $anonsub; } sub Alrm { for (keys(%times)) { if (time() >= $times{$_}) { ${subs{$_}}(); delete $times{$_}; } elsif (time() < $times{$_}) { next; } } alarm 1; } $SIG{ALRM} = \&Alrm; alarm 1; print gmtime(time()).chr(10); sub DoStuff { print gmtime(time()).chr(10); after(time+1, \&DoStuff); } after(time+1, \&DoStuff); 1 while 1;