my ($correct, $incorrect) = 0; for(0 .. length($string)-1) { if( substr($string, $_, 1) eq substr($guess, $_, 1) ) { $correct ++; } else { $incorrect ++; } }