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];