#!/usr/bin/perl -w use strict; my $childLimit = shift @ARGV; #get total number of children my @pids = (); #array of pids of children for(my $i = 0; $i < $childLimit; $i++) { if( !( $pids[$i] = fork() ) ) { # in the child callChildSub(); exit(0); # exit from the child process IMPORTANT } } foreach my $pid (@pids) { waitpid $pid, 0; } sub callChildSub() { print "I am the child with pid $$.\n"; }