#!/usr/bi/perl $driver = "./dirlist.csv"; open DRV , $driver || die "Cannot open $driver: $!"; while( ){ chomp; my ($dirname) = shift; checkExistingDates($dirname); } close DRV; sub checkExistingDates{ my $dirname = shift; my @datelist = ("20030901", "20061017", "20050406", "20070101", "20080202"); #the file list should be read from the $dirname, for testing using hard values my @fileslist = ("DIR22.20060816", "DIR22.20050919", "DIR22.20061017", "DIR22.20060516", "DIR22.20050406"); my @matched; foreach my $date (@datelist}){ @matched = grep{$date} @fileslist; } print Dumper @matched; }