srand; # seed the random generator open(FILE,"file.txt"); # put the file contents into an array @file = ; close(FILE); foreach (@file) {chomp} # remove the newlines $line = $file[rand($#file)]; # select a random line