use strict; use warnings; use AnyEvent; use AnyEvent::Fork; use feature 'say'; package Some; # Some::function might look like this - all parameters passed before fork # and after will be passed, in order, after the communications socket. sub funct{ my ($fh, $str1, $str2, $fh1, $fh2, $str3) = @_; print scalar <$fh>; # prints "hi #1\n" and "hi #2\n" in any order } package main; my $pool = AnyEvent::Fork ->new ->send_arg ("str1", "str2") ; for (1..2) { $pool ->fork ->send_arg ("str3") ->run ("Some::funct", sub { say 'Inside anonysub'; }); } say 'Outside pool loop'; AnyEvent->condvar->recv;