http://www.perlmonks.org?node_id=156603


in reply to Running subroutines asynchronously

use Proc::Forkfunc;
use strict;

$|++; # autoflush/unbuffer

my @child_args = qw(1 2 );

forkfunc(\&child_func, @child_args);
forkfunc(\&child_func, 3);
forkfunc(\&child_func, 4);
forkfunc(\&child_func, 5);

sub child_func {
    # sleep for rand(3)*rand(3)
    select undef, undef, undef,  rand(3) * rand(3);

    print shift(@_);
    print "\n";
}
Proc::Forkfunc has the annoying habit of printing to STDERR "call to child returned", but it's not a complex module, and if you crack it open (look at the source), you can easily figure out what's goin on. You should also take a look at perlfork. This will work for most systems, but remember, forking is experimental on Win32 machines, and is not available before v5.6, but there is an alternative, Win32::Process.