#! perl -slw use strict; use threads; use threads::shared; our $N ||= 100; our $M ||= 2e6; my %hash : shared; sub process { my $tid = threads->self->tid; for( 1 .. $N ) { for( keys %hash ) { lock( %hash ); printf "$tid: (%d) $_ => %s\n", length $hash{ $_ }, substr $hash{ $_ }, 0, 50; } } } $hash{ $_ } = chr( 64 + $_ ) x $M for 1 .. 25; my @threads = map{ threads->create( \&process ) } 1 .. 10; $_->join for @threads;