#!/usr/bin/perl -wT use strict; %ENV = (); # clean out the %ENV hash to prevent mischief $ENV{PATH} = '/bin'; my @pids; # array for storing childrens pids my $cmd = 'sleep 2; echo "I am child $$"'; # command children will execute for (1..4) { my $childpid = fork() or exec($cmd); # fork off a child push(@pids,$childpid); # store the childs pid in @pids } print "My Children: ", join(' ',@pids), "\n"; waitpid($_,0) for @pids; # wait for children to finish print "Children are done\n";