use MCE::Simple -strict, ( spawn_limit => 2, # MCE::Child processes max_workers => 2, # number of MCE workers init_relay => 1, # define to enable MCE::relay ); # Run MCE in the foreground. mce_foreach my $i (10..18) { MCE::relay { # output orderly say "$$: $i"; }; } # Run MCE in the background. spawn sub { mce_foreach my $i (20..28) { MCE::relay { say "$$: $i"; }; } }; sync; # Spin a worker per each input element. # Up to "spawn_limit" will run simultaneously. # Blocking otherwise, until next availability. spawn my $i (30..38) { say "$$: $i"; } sync;