http://www.perlmonks.org?node_id=64502


in reply to Counting number of characters in a string

Count the dots using a regular expression:
$str="There's many more ways to do it.\n"; $str =~ tr/\000-\xff/./; while ( $str =~ /(.)/g ) { $count++; }
You can check this using a different method:
$count2++ while chop $str; $count eq $count2 or warn "there's something wrong with this code.\n";


p