# main loop while (1) { # do stuff # check for event my $event = check_for_event(); # now check for event and fork a child to deal with it # fork returns 0 to child, child PID to parent, undef if fails if ( $event and fork ==0 ) { # this is a child process sleep $whatever; do_stuff($event); # kid has done what was required so kill it exit 0; } # parent is continuing here, kid never gets here }