my %hash; open DATA,") { chomp; my @vars=split /,/,$_; ## ignore it if no first value next unless defined $vars[0]; ## I will also assume your regex were to remove all ## leading and trailing spaces. If that is true, ## you did it incorrectly map { s/^\s*//; s/\s*$// } @vars; ## and store it based on the 3rd var push @{$hash{$vars[2]}},@vars[0,1,3]; } close DATA; #### $hash{somevalue}[0] = the first value (your $var1) $hash{somevalue}[1] = the second value (your $var3) $hash{somevalue}[2] = the third value (your $var4)