my $string = "1:1,2:1,3:2,500:2,505:1"; my %hash = split /[:,]/, $string; my @array = keys %hash;