#!/usr/bin/perl -w use strict; use File::Basename; my %files; my @searchfiles = ("foo", "bar", "xxx"); open( INDEX, "< index" ) or die "Couldn't read index : $!\n"; # now we read every filename from our index file and put it in the hash. # If we are only checking for one file, we could do the check right here # in the loop. # We also strip the path from the filename, as we will be searching for files # (and if we already knew the path to the file, -e would be faster :) ) # This method dosen't care for duplicates. If we have two files with the same name, # only the last file will be reported. my $filename; while( ) { $files{ basename( $_ ) } = $_; }; close INDEX; # And now we check if the filenames are in the hash foreach (@searchfiles) { print $files{ $_ } if (exists $files{ $_ }); };