in reply to Re^2: Which is more faster? While or tr///
in thread Which is more faster? While or tr///

Couldn't you just put all the weights in a lookup table, and then iterate once over the characters of the string?  Something like this:

my %weight = ( A => 0.6562, B => 0.3571, #... z => 0.42, ); for my $ch (split //, $string) { $count += $tbsz * $weight{$ch}; }

Or (if the string is huge)

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

(And if ord($ch) of the characters is within a narrow range (such as ASCII), you could also use an array, and store the weights under $array[ord($ch)] — which might be a tad faster than a hash.)