use strict; use warnings; use Data::Dumper; my %hash; while (my $line = ) { chomp $line; my ( $key, $value ) = split /\s*::=\s*/, $line; if ( $key and $value ) { push @{$hash{$key}}, $value; } } print Dumper \%hash; __DATA__ A::=B C::=D A::=C