#!/usr/bin/perl use strict; use warnings; BEGIN { # Move to running in background. if (!@ARGV || $ARGV[0] ne '--nobkg') { $SIG{CHLD} = 'IGNORE'; require IPC::Open3; IPC::Open3::open3( '<&STDIN', '>&STDOUT', '>&STDERR', $^X, $0, '--nobkg', @ARGV ); exit; } } use threads; sub my_sub { open(my $fh, '>', "$0.".threads->tid() ) or die; print $fh 'text'; sleep(10); } my $thread1 = new threads(\&my_sub); my $thread2 = new threads(\&my_sub); $_->join() for $thread1, $thread2;