use strict; use warnings; use 5.012; use threads; use threads::shared; my $counter :shared; $counter = 1; my $name = 'Joe'; sub do_stuff { my $thread_id = shift; sleep rand 10; say "thread number $thread_id"; say "count: $counter"; $counter++; say $name; $name = "Cathy"; } my @threads; for my $thread_number (1..10) { push @threads, threads->create('do_stuff', $thread_number); } for (@threads) { $_->join; } --output:-- thread number 5 count: 1 Joe thread number 9 count: 2 Joe thread number 3 count: 3 Joe thread number 7 count: 4 Joe thread number 10 count: 5 Joe thread number 4 count: 6 Joe thread number 6 count: 7 Joe thread number 8 count: 8 Joe thread number 1 count: 9 Joe thread number 2 count: 10 Joe