my $string = "1:1,2:1,3:2,500:2,505:1"; my %hash = my @array = split /[:,]/, $string; @array = @array[grep $_%2==0, 0..$#array];