in reply to Optimizing a string processing sub

Here's another way to do it:

sub score { my ($x, $y) = @_; return $words_equal if ($x eq $y); my $c = 0; index($y, $_)+1 && $c++ for split //, $x; return $c; }

The real question is whether your code is actually doing what you expect. Your function is not commutative. For example, score('quuux', 'quack') does not return the same thing as score('quack', 'quuux') does. (The first is 4 the second is 2.)

-sauoq
"My two cents aren't worth a dime.";