while (<>) { if ($_ eq /yes/ or /y.*/) { print "\n$word1 $word2 $word3 $word4\n"; exit; } else { exit; } }