my @list = (@lines); foreach (@lines) { my @fields = split /,/; if ( $fields[2] eq '1' || $fields[2] eq '0' ) { #@arr1 = do {"@fields[4]\n"}; push @list, $fields[4]; @list =uniq @list; print "$_\n" for @list; @listx = "$_\n" for @list; print "LETING US SEE @listx"; } } @listx; my %ndmhash; my @listoffiles = ("CORP-INV-STAGE-NDM"); for (@listoffiles) { { my $file = "/tmp/host/" . $_ . '.txt'; open(my $fh, '>', $file) or die "Cannot open file '$file' for writing: $!"; my $name2 = $file; #$name2 =~ s/\CORP//g; #$name2 =~ s/*CORP-/ /g; $name2 =~ s/'$//; rename($file, $name2); $ndmhash{$_} = $fh; } } my $pattern = join '|', @listoffiles; $pattern = qr/$pattern/; open my $fh1, '<', "/tmp/host/mon2a" or die "unable to open file 'file' for reading : $!"; while (<$fh1>) { chomp; my @fields = split(',', $_); local $" = ','; if (($fields[2] eq '1' || $fields[2] eq '0') && /$pattern/) { print { $ndmhash{$fields[4]} } $fields[0], ',', $fields[32], ',', $fields[6], "\n" if /MONTHLY/ && !/,-,/ && !/SM3/ && !/FISH/; print { $ndmhash{$fields[4]} } $fields[0], ',', $fields[34], ',', $fields[6], "\n" if /MONTHLY/ && !/,-,/ && /BASKET/; print { $ndmhash{$fields[4]} } $fields[0], ',', $fields[35], ',', $fields[6], "\n" if /MONTHLY/ && !/,-,/ && /FORM/; } } { close $ndmhash{$_} or die "Cannot close file '$_': $!"; }