use strict; use threads; use threads::shared; my $flag : shared = 1; sub thread_code { while( $flag ) { # Do your thread stuff here # but make sure it loops every now and then # so that you will see the flag change } } my @threads = map{ threads->new( \&thread_code ) ; } 1 .. 4; ... # when you get told to finish by the user # or otherwise decide to exit. EXIT{ $flag = 0; # tell the kids its time to go $_->join() for @threads; # Wait for them # and go. }