#!/usr/bin/perl -w use strict; # this is just so that glob() whitespace handling is sane use File::Glob qw(bsd_glob); my $fname = "empty"; my @found_files; while (! @found_files){ print "Please enter Filename: "; chomp($fname = ); @found_files = glob( "/Users/johnsmith/data/$fname*" ); if (@found_files != 1) { if (@found_files == 0) { print "File '/Users/johnsmith/data/$fname*' does not exist.\n\n"; } else { print "There are multiple files matching '/Users/johnsmith/data/$fname*':\n"; print "$_\n" for @found_files; }; }; } print "I have found this '$found_files[0]' in your directory\n\n";