#! perl ... # main.script my $originalPid = $$; END{ return if $$ == $originalPid; require threads; threads->exit; } use Foo; use Bar; ...