my $cnt = $str =~ tr/1//; #### my %char_cnt; ++$char_cnt{$_} for split //, $str;