use MCE::Flow max_workers => 8; my $file1 = "/path/to/file1.txt"; my $file2 = "/path/to/file2.txt"; unlink $file1 if -e $file1; unlink $file2 if -e $file2; mce_flow sub { my $wid = MCE->wid; if (MCE->wid % 2 == 0) { MCE->sendto("file:$file1", "sunny day from $wid\n"); } else { MCE->sendto("file:$file2", "raining day from $wid\n"); } }; #### use MCE::Loop chunk_size => 1, max_workers => 8; my @input = (100..199); open my $fh_1, '>', '/path/to/file1.txt'; open my $fh_2, '>', '/path/to/file2.txt'; mce_loop { my ($mce, $chunk_ref, $chunk_id) = @_; if ($chunk_id % 2 == 0) { MCE->say($fh_1, "id: $chunk_id: input $_"); } else { MCE->say($fh_2, "id: $chunk_id: input $_"); } } @input; close $fh_1; close $fh_2;