#!/usr/bin/perl @dirname; $dirname[0]="TestList1.log"; $dirname[1]="TestList2.log"; $dirname[2]="TestList3.log"; for(1..4) { my $pid = fork(); if ($pid) { # parent push(@childs, $pid); print "we are in the parent bus \n"; waitpid($pid,0); } elsif ($pid == 0) { # child # here I want to read a different file each child # so child 1 would read dirname[0] # so child 2 would read dirname[1] # so child 3 would read dirname[2] # and they would all do the same thing, # but on different files # something like: #$mm = @child array's element number open (filelist, @dirname[$mm]) || die "couldn't open the file!"; @filename; @filename = ; print "@filename \n"; sleep 5; exit(0); } else { die "couldn’t fork: $! \n"; } print "LAST IN FOR \n"; } print "AFTER FOR \n";