#!/usr/bin/perl use warnings; use strict; use threads; use threads::shared; use Data::Dumper; sub test { # my %h ; shared; #dosn't work our %h : shared; #works for (1 .. 3) { threads->create(sub { my $n = shift; lock %h; $h{$n} = rand; }, $_)->join; } return %h; } print Dumper {test()};