#!/usr/bin/perl use strict; use warnings; use threads; use threads::shared; use Tie::Watch; my $count:shared=0; my $thread = threads->new( \&launch_thread )->detach; my $watch = Tie::Watch->new( -variable => \$count, # -debug => 1, -fetch => \&fetch, -store => \&store, -destroy => sub {print "Final value=$count.\n"}, ); while(1){} sub launch_thread { while (1){ $count++; print "$count\n"; sleep 1; } } sub store { print "changed\n"; } sub fetch{ print "fetched @_\n"; }