#!/usr/bin/perl -w use threads; use threads::shared; my $status : shared; my $thr_work = threads->create( sub { # do some work. lock $status; return if $status; $status = "done"; cond_signal $status; return @whatever; } ); threads->create( sub { sleep 300; lock $status; return if $status; $status = "timed_out"; cond_signal $status; } )->detach; { lock $status; cond_wait $status until $status; if ( $status eq "done" ) { my @results = $thr_work->join; # process @results. } else { print "Timed out\n"; $thr_work->detatch; } }