#!/usr/bin/perl -w use warnings; use strict; use threads; use threads::shared; my @Array : shared = (); my $thr = threads->create( \&handle_array , \@Array ); while( 1 ) { do_something(\@Array); printf "Main: Number of files: ". scalar(@Array) . "\n"; sleep 5; } sub do_something { my ( $Array_ref ) = shift; my %hash : shared = ( file => 'test1.zip', price => '10.00', desc => 'the 1st test' ); push @{ $Array_ref } , \%hash; } sub handle_array { my ( $Array_ref ) = shift; while (1) { printf STDOUT "Thread: Number of elements before: %d\n", scalar @{ $Array_ref }; my %hash :shared = ( file => 'test1.zip', price => '10.00', desc => 'the 1st test' ); push( @{$Array_ref} , \%hash ); printf STDOUT "Thread: Number of elements after: %d\n", scalar @{ $Array_ref }; sleep 10; } }