my $possible_file = shift; my $found_file = find_file($possible_file); { local *INPUT; open(INPUT, $found_file) or die "Can't open $found_file: $!"; my $line = ; # do something with $line close INPUT or die "Can't close $found_file. Bogosity: $!"; } sub find_file { my $file = shift; while (-d $file) { # the next line may differ on Win/Mac/Un*x my @files = glob("$possible_file/*.*"); foreach (@files) { find_file($_); } # we're not dealing with a file anymore, so return } return $file; }