my @array = qw/0:2 4:6 8:12/; my %hash; foreach my $ele (@array) { my @temp = split /:/, $ele; $hash{$_}++ foreach $temp[0]..$temp[1]; }