#!/usr/bin/perl use warnings; use strict; use threads; use threads::shared; $|=1; #turn off buffering my @hosts_shared : shared; #declare as shared before setting value @hosts_shared = (1,2,3,4,5); print "@hosts_shared\n"; my $thread = threads->new(sub { print "Run the thread! array should be modified\n"; #modify shared array push @hosts_shared, 42; })->detach(); sleep 1; # cheap hack to allow thread time to work print "@hosts_shared\n"; print "Hit enter to exit\n"; <>;