use File::Map qq(map_file); use MCE; use MCE::Candy; use Path::Iterator::Rule; my $rule = Path::Iterator::Rule->new->file->name(qr/[.](html)$/); my $iterator = $rule->iter_fast("topdir"); open my $fh_out, ">:utf8", $self->fn_out; my $mce = MCE->new( gather => MCE::Candy::out_iter_fh($fh_out), max_workers => 'auto', user_func => \&parse_file, )->spawn; $mce->process($iterator); sub parse_file { my ( $mce, $chunk_ref, $chunk_id ) = @_; map_file my $text, $chunk_ref->[0], '<'; my (@posts) = $text =~ m/ \<\!--XXXX:\ (\d+)--\>\<\!--YYYY:\ (\d+).+? (?:<\!--AAAAA--\>(.*?)\<\!--\/AAAAA--\>|) \<\!--BBBB--\>(.*?)\<\!--\/BBBB--\>.+? \<\!--CCCC--\>(.+?)\<\!--\/CCCC--\> /msgx; … Do some stuff with posts and place results in multiline string $output $mce->gather( $chunk_id, $output ); }