#getting the ids from first directory sub doFile($) { my ($fn) =@_; chomp($fn); print "opening $fn\n"; my $fh = IO::File->new($fn, 'r'); my @msgLines; if( defined $fh){ while(my $l = <$fh>) { push @msgLines, $l; if($l =~ m"\s*\$") { #my $msg = join('', @msgLines); my $id; if(grep{ m"http://.*foo.com" } @msgLines) { #store the @msglines into an array, this array can serve as source for searching for reponses from first directory, need to do something similar for the rest of directories. $id = grep { $_ =~ m"(\d+)"; } #@msgLines; # $id =~ m"(\d+)"; push @IDs, $id; } @msgLines = (); } } } else{ die "Cannot open file $!\n";} } my @firstdir=@{$logfiles[0]}; my $path=$logdirs[0]; foreach (@firstdir) { my $curpath=sprintf($path.'/'.$_); print"In foreach trying to open $path\n"; doFile($curpath); }