my %hash; my ($name, $id, $comment); while(){ chomp; my ($name, $id, $comment)=split; $hash{$name}{$id}= $comment; #adding comment to related $name/$id.. #push @{$hash{$name}{$id}}, $comment; #create an anonymous array #in case more than one $comment or other variables related to same $name/$id }