#!/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; push( @{$Array_ref} , {file => 'test1.zip', price => '10.00', desc => 'the 1st test'} ); sleep 10; } sub handle_array { my ( $Array_ref ) = shift; while (1) { printf STDOUT "Thread: Number of elements before: %d\n", scalar(@{$Array_ref}); push( @{$Array_ref} , {file => 'test1.zip', price => '10.00', desc => 'the 1st test'} ); printf STDOUT "Thread: Number of elements after: %d\n", scalar(@$Array_ref); sleep 10; } }