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;