while (defined($filename = $term->readline('>'))) { #### use Term::ReadLine; # Direct notation recommended over indirect notation. my $term = Term::ReadLine->new('test'); for (;;) { $filename = $term->readline('>'); die("Unable to read in filename\n") unless defined $filename; print "checking for $filename...\n"; last if -e $filename; print "File not found. Please try again\n"; } print "filename is ~~$filename~~";