use threads; use threads::shared; my ($global):shared; my $handler=threads->create(\&handler)->detach; do { print "Enter a value for shared global variable ( x = exit ): ";chomp($global=<>); sleep(3); } while($global ne 'x'); sub handler { my $global_old=$global; while(1) { if($global ne $global_old) { print "User changed the global variable to '$global'.\n"; $global_old=$global; } sleep(1); } }