#!perl -w use strict; use warnings; use feature 'say'; use AnyEvent::Util; my $spawn_complete = AnyEvent->condvar; sub spawn { my $name = shift; my $sleep = rand 10; $spawn_complete->begin; fork_call { say "$name($$) about to sleep for $sleep"; sleep $sleep; } sub { say "$name Awake!"; $spawn_complete->end; }; } # Run 5 long processes in the background spawn $_ for qw(abc def ghi jkl mno); # Wait for all background tasks to finish $spawn_complete->recv; say "All done";