my $count= 0; for(0..255){ my $c= pack "C", $_; $count += () = $str =~ /\Q$c\E/g; }