... while ($string =~ /(.)/gs) { $count += $tbsz * $weight{$1}; }