my $txt1 = "0101010101"; my $count; my %hashofuniq; my @txt1 = split ('',$txt1); @hashofuniq{@txt1} = 1; foreach (keys %hashofuniq){ $count++; } print "[$count]\n";