open my $fh2, '<', '/tmp/location' or die "unable to open file for reading : $!"; open my $fh1, '<', '/tmp/carlist' or die "unable to open file for reading : $!"; chomp(my @carlist = <$fh1>); print "these are the policies @carlist\n"; close $fh1; my $pattern = join '', @carlist; my @strings; while (<$fh2>) { my @fields = split(',', $_); local $" = ','; if ( $fields[1] eq '1' || $fields[1] eq '0') { push @strings, $_ if /$pattern/; print $fh3 "@fields[0,4]\n" if /engineer/ && !/,-,/; } } close $fh2; close $fh1; close $fh3;