sub parse_file { my ($file_path,$href) = @_; open(my $fh, '<', "$file_path") or return 0; while (my $line = <$fh>) { chomp($line); unless ($line =~ /\A[^,]+(?:,[^,]+){5}\z/) { next; } my ($key,$group,$value,$version,$file,$count) = split(/,/,$line); push @{ $href->{test} }, { group => $group, values => [ sort uniq $value, @{ $href->{values} // [] } ] }; } close ($fh); return 1; } foreach my $dir (sort(@list_of_dirs)) { my ($all,%data); $all = $dir."/"."galish"; prase_results_raw($all,\%data); push(@all_data,\%data); }