open(my $fh, '<', "$file_path") or return 0; while (my $line = <$fh>) { # ........... # ........... # Additional operations of the lines of the file # ........... # ........... my %a; # temp hash $a{"group"} = $group; if (defined($href->{"values"})) { $a{"values"} = [sort(uniq($value,@{$href->{"values"}}))]; } else { push(@{$a{"values"}},$value); } push(@{$href->{"test"}},\%a); }