use strict; use warnings; use MCE::Child; use MCE::Channel; my $chnl = MCE::Channel->new( impl => 'Simple' ); # spin up worker early before creating big hash mce_child { while ( my ($cmd, @args) = $chnl->recv ) { local ($?, $!); system($cmd, @args); $chnl->send2($?, $!); } }; # create big hash my %big_hash; my ($status, $errmsg); # pass command and optionally args to worker $chnl->send('ls'); ($status, $errmsg) = $chnl->recv2; # ditto, sleep for 2 seconds $chnl->send('sleep', '2'); ($status, $errmsg) = $chnl->recv2; # notify no more work, then reap worker $chnl->end; MCE::Child->waitall;