use threads; use threads::shared; my $var = 1; my $svar : shared = 2; my %hash : shared; ... create some threads ... $hash{a} = 1; # all threads see exists($hash{a}) and $hash{a} == 1 $hash{a} = $var # okay - copy-by-value: same effect as previous $hash{a} = $svar # okay - copy-by-value: same effect as previous $hash{a} = \$svar # okay - a reference to a shared variable $hash{a} = \$var # This will die delete $hash{a} # okay - all threads will see !exists($hash{a}) #### use strict; use warnings; package Foo; sub new { my ($class, $arg) = @_; my $this = bless {}, $class; $this->{args} = undef; return $this; } sub set { my ($this, $arg) = @_; $this->{args}[0] = $arg; # setting an entry in a shared array reference } 1; # End of the module, and now a test script use strict; use warnings; use Foo; use threads; use threads::shared; my $foo = new Foo(); my $nested_array = []; my $nested_string = 'bar'; share($foo); share($nested_array); share($nested_string); $foo->{args} = $nested_array; # set the shared array reference # pass in a reference to the shared scalar my $thr1 = threads->create(sub { $foo->set(\$nested_string) }); # If in Foo::set we manually set the argument passed, say, to 'quux', # the object will contain that string rather than 'bar', # proof that we do indeed have a shared nested reference. $thr1->join(); print $foo->{args}[0];