letters is not an array. It is a string. The
$#letters syntax is for arrays (it returns the last index of the array...or one less than the length of the array). Perhaps you want to use the
length function. Are you using
strict? Though the capital "W" in the while is your syntax error, as has already been pointed out.