最简单的方法(恕我直言)是fork一个子流程并让它完成工作。Perl 线程可能很痛苦,所以我尽可能避免使用它们。
这是一个简单的例子
use strict;
use warnings;
print "Start of script\n";
run_sleep();
print "End of script\n";
sub run_sleep { 
    my $pid = fork;
    return if $pid;     # in the parent process
    print "Running child process\n";
    select undef, undef, undef, 5;
    print "Done with child process\n";
    exit;  # end child process
}
如果您在 shell 中运行它,您将看到如下所示的输出:
Start of script
End of script
Running child process
(等待五秒钟)
Done with child process
父进程将立即退出并将您返回到您的 shell;子进程将在五秒钟后将其输出发送到您的 shell。
如果您希望父进程在子进程完成之前一直存在,那么您可以使用waitpid.