my $choice; while (1) { print "\nDo you want to continue : "; chomp($choice = ); if ($choice eq "y" || $choice eq "n") { last; } else { print "\nERROR:Invalid Choice\n"; } }