#!/usr/bin/env perl use strict; use warnings; my $file = '/no_such_file.txt'; my $infh; while (not open $infh, '<', $file) { print "Could not open $file: $!. Please provide another:\n"; chomp ($file = ); } my $first = <$infh>; print "First line of $file: $first"; close $infh; exit;