In Perl's hashes, keys mush be unique. When you define the hash, each repeated key just overwrites the older value. In the real situation, you are probably getting the keys and values from something else than the source code itself, so you can concatenate the values:
while (get_tuple($key,$value)) {
$hash{$key} .= $value;
}
#!/usr/bin/perl --
use strict;
use warnings;
use List::Tuples qw' tuples ';
Main( @ARGV );
exit( 0 );
sub Main {
my %hash ;
for my $tuple (
tuples [2] =>
rat => "acggghhh",
mat => "dhhdhdhdh",
rat => "fhhfjfjj",
rat => "dggdgdgdg"
)
{
$hash{ $tuple->[0] } .= $tuple->[1];
}
while ( my( $key, $value ) = each %hash ) {
print "$key and $value \n";
}
}
__END__
rat and acggghhhfhhfjfjjdggdgdgdg
mat and dhhdhdhdh