#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my @times = qw(1000 1000 1000 1010 1010 1010); my %data; foreach my $key (@times) { $data{$key}++; } print Dumper(\%data); #### $ perl timehash1.pl $VAR1 = { '1000' => 3, '1010' => 3 }; #### #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my @times = (1000 => 'hello',, 1000 => 'world', 1000 => 'foo', 1010 => 'bar', 1010 => 'baz', 1010 => ['hello world', 'hallo welt'], ); my %data; while(@times) { my ($key, $val) = (shift @times, shift @times); push @{$data{$key}}, $val; } print Dumper(\%data); #### $ perl timehash2.pl $VAR1 = { '1010' => [ 'bar', 'baz', [ 'hello world', 'hallo welt' ] ], '1000' => [ 'hello', 'world', 'foo' ] }; #### while(@times) { push @{$data{shift @times}}, shift @times; }