#!/Usr/local/bin/perl; use Tie::File; use Getopt::Long; use warnings; #string to search for my($target1) = '6169600047'; #files and directories my($indir) = "c:/FAMD_EDI"; my($outdir) = "c:/FAMD_EDI"; my($outfile) = "FAMD_EDI_Master.txt"; open(OUTDIR, $outdir); open(OUTFILE,">$outdir/$outfile") or die "Cannot create output File"; opendir(MYDIR, $indir) or die "can't open dir $indir: $!"; while (defined($infile = readdir(MYDIR))) { next if $infile =~ /^\.\.?$/; open(FILEHNDL, "$indir/$infile") or die "Cannot open input file $!"; while ($line = ) { chomp($line); #print "line= $line\n"; @cols = split(/|/, $line); if ($cols[11] = $target1) { #complete processing } } close(FILEHNDL); } close(OUTFILE); closedir(MYDIR);