use strict; use warnings; use threads; use threads::shared; my @dirs = qw( a b c d e f ); my %hash = map { $_ => shared_clone({}) } @dirs; my @thrs; foreach my $dir (@dirs) { if (-e "$dir/syn.log") { push @thrs, threads->create(\&process_1_file, $dir, "syn.log"); } } $_->join for @thrs; print $hash{"a"}{"area"}, "\n"; sub process_1_file { my ($dir, $file) = @_; open(my $fh, "$dir/$file") or die "cannot open $dir/$file $!"; while (<$fh>) { chomp; if ($_ =~ /^area=(.*)/) { $hash{"$dir"}{"area"} = $1; } } }