#! /usr/bin/perl open( FILE, "test.txt" ) || die $!; $mytext = do { local $/; ; }; $mytext = lc($mytext); $mytext =~ s/[^a-z|]/ /g; @wordarray = split( //, $mytext ); print "@wordarray \n "; $len = @wordarray; print "\n the lenght of the array is : $len "; $i = 0; $j = 0; $iter = 0; while ( $i <= $len - 1 ) { print " \n Value of i is : $i "; print " \n Value of j is : $j "; print " \n Value of character in array is : $wordarray[$i] "; print " \n Enter the character : "; $line = ; chomp($line); # remove the trailing line termination if(length($line) > 1) { print "extra characters \"" . substr($line,1) . "\" ignored\n"; } $char = substr($line,0,1); print " input is $char "; chomp($char); print " \n inputted character is : $char "; if ( $char eq $wordarray[$j] ) { print "Correct !!"; $iter++; $count[$i] = $iter; $j++; $i++; $iter = 0; } else { print "\n Wrong please try again "; $iter++; print "\n Number of attempts : $iter "; } }