my %found; my %active; # sighandler for sigchild $SIG{'SIGCHLD'} = sub { my $pid = waitpid; delete $active{$pid}; }; while(running) { if(my $serverid = new_server_found()) { $found{$serverid} = { 'name' => $servername, 'otherinfo' => $otherinfo, }; my $pid = fork; if(defined $pid) { # fork ok if($pid == 0) { # this is in the child do_all_stuff_necessary_for_hardening(); exit $rc; } else { # this is parent # You have the pid and you know that this # fork was concerning a server you found # probably you want to store this information $active{$pid} = $serverid; } else { # no fork => error handling die ("FATAL: Something went wrong"); } } sleep(1); }