fork_call every 'n' seconds in AnyEvent
Ok, here is a smaller scope for $running and do_work() doesn't need to bother with it,

sub do_work {

    my $worker_cv = AnyEvent-&gt;condvar;

    $worker_cv-&gt;begin;
    fork_call {
        work1();
    } sub {
        $worker_cv-&gt;end;
    };

    $worker_cv-&gt;begin;
    fork_call {
        work2();
    } sub {
        $worker_cv-&gt;end;
    };

    return $worker_cv;
}


my $running;
my $timer = AnyEvent-&gt;timer(
    interval =&gt; 5,
    cb =&gt; sub {      
        return if $running;

        $running = 1;
        do_work()-&gt;cb(sub{
            $running = 0;
        });
    }
);