my $j = 0; if ((my $pid = fork()) == 0) { # this runs in child process do {sleep 0.5; spin($j)} while 1; # normally we should put some kind of exit statement here, but the loop above is infinite } elsif ($pid > 0) { # parent/main process ...; # put your loop here kill 1, $pid; # stop the spinner process waitpid $pid, 0; # this should help against zombies } else { # fork returned undef die "fork: $!\n"; }