use POSIX; $SIG{CHLD} = sub { while( ( my $pid = waitpid(-1, POSIX::WNOHANG()) ) > 0 ){ ## cleanup code... ## you probably should save the forked ## pids and make sure that the result of ## waitpid is indeed your child } } foreach my $nod ( @devices ) { my $pid = fork(); if( !$pid ) { ## child... } }