use warnings; use strict; my $file; #create an inifite loop while (1) { # ask the user for filename print "Enter filename > "; chomp( $file = ); # Exit the loop, if the # filename exists and it's a file # else redo if ( -e $file && -f _ ) { #Note HERE last; } else { redo } } open my $fh, '<', $file or die "can't open file: $!"; ...