my $found; while ( my $file = readdir(DIR) ){ $found = $file, last if $file=~/^myname\.doc$/i; } closedir(DIR); print "Found: $found" if $found;