my %hash; foreach my $dir (@dirs) { if (-e "$dir/syn.log") { proccess_1_file("$dir/syn.log"); } } sub proccess_1_file { my $file = $_[0]; open(my $fh, "$file") or die "cannot open $file $!"; while (<$fh>) { chomp; my $line =$_; if ($line =~ /^area=(.*)/) { $hash{"$dir"}{"area"} = $1; }