my $pid1 = background("command > some-file"); my $pid2 = background("other-command > some-other-file"); my $tail_pid = background("tail -f some-file"); ...do stuff... if (waitpid $pid1) { kill 9, $tail_pid; } ... sub background { defined(my $pid = fork) or die "unable to fork: $!"; if ($pid == 0) { exec(@_); exit 1 } $pid; }