{ my $running : shared = 0; local %ENV = %ENV; $ENV{ FOO } = 'BAR'; async{ my $pid = open ...; $running = 1; ... kill ... }->detach; ## Wait until the kid is spawned before exiting the scope. sleep 1 until $running; } ## And repeat till done.