use strict; use warnings; "print "This program will ask the user random questions from a file un +til all the questions have been answered.\n"; open(QUESTFILE, 'questions.txt') or die "Couldn't open questions.txt: $!\n"; my @questions = ; # slurps up the entire file close(QUESTFILE); #### # this opens the answers file for append open(ANSFILE,">>answers.txt") or die "Couldn't open answers for appending: $!\n"; # rather than a while loop and a variable just use a foreach # loop with a range ... $_ will contain the number foreach(1 .. 10) { print $questions[ int( rand( scalar(@questions) ) )]; my $ans = uc(); print ANSFILE $ans; } close(ANSFILE); exit;