#! perl -slw use strict; use Carp; use threads; use threads::shared; $| = 1; our $N ||= 2; our $SIZE ||= 1e6; my $semaphore :shared = 0; my $running : shared = 0; 'abc' =~ m[b] and print "$`:$&:$'"; ## Use ampersand. my $bigString = 'ACTG' x $SIZE; for ( 1 .. $N ) { async { printf "Thread %s starting\n", threads->tid; ++$running; my $count = 0; while( $bigString =~ m[ACTG]g ) { #lock $semaphore; #print threads->tid, ' : ', pos( $bigString ); ++$count; } --$running; printf "Thread %s stopping ($count)\n", threads->tid; }; } Win32::Sleep 100 until $running; Win32::Sleep 100 while $running;