use strict; #use warnings; my $record; my $tele; my $esn; my $coid; my $error; my $comptn; sub search_tn; my $directory = "C:\\TEMP\\files"; opendir( DIR, $directory ) || die "Unable to open directory - $!\n"; my @files = grep /^R/, readdir( DIR ); closedir( DIR ); open( OUTFILE, "> $directory\\search_results.txt" ) || die "Unable to open write file! - $!\n"; open (COMPFILE, "c:\\temp\\files\\search tns.txt") || die "Unable to open search file! $!\n"; while () { $comptn = substr $_, 0,10; search_tn($comptn); } sub search_tn { foreach my $file (@files) { open( FH, "$directory\\$file" ) || die "Unable to open $file - $!\n"; while( ) { my @record = split /\|/, $_; next until $. > 1; if ($record[0] eq "TLR") { } else { $tele = substr $record[2], 3, 10; if ($comptn == $tele) { print OUTFILE "====TN Found====\n"; print OUTFILE "FILE: $file\n"; print OUTFILE "TN: $tele\n"; $esn = substr $record[3], 3,5; print OUTFILE "ESN: $esn\n"; $coid = substr $record[4], 3,5; print OUTFILE "COID: $coid\n"; $error = substr $record[9], 3,3; if ($error == "") { print OUTFILE "Error: no error \n\n"; } else { print OUTFILE "Error: $error \n"; print OUTFILE "================\n\n"; } } } } close (FH); } } #### if ($comptn != $tele) { print OUTFILE "TN $comptn not found \n"; }