#!/usr/bin/perl -w $|++; use strict; use threads; use threads::shared; # Flag variable we use to stop the 2nd thread my $complete : shared = 0; # Create the thread my $thread = threads->create(\&dothis); # Code of main thread goes here sleep 5; # Change the flag variable so the thread ends $complete = 1; # Join the threads together $thread->join(); # End of the program exit; sub dothis { until($complete) { print "#"; sleep 1; } print "\n"; }