my $calls_dir2 = "$response/Bing/1Parsed/Html"; my $parsed_dir = "$response/Bing/1Parsed/Html2"; unless ( -d $parsed_dir ) { make_path( $parsed_dir , { verbose => 1, mode => 0755 } ); } open( my $fh2, '<', $parse1file ) or die $!; chomp( my @parse_terms1 = <$fh2> ); close($fh2); open( $fh2, '<', $parse2file ) or die $!; print "parse1file=$parse1file\n"; print "parse2file=$parse2file\n"; for my $parse1 (@parse_terms1) { seek( $fh2, 0, 0 ); while ( my $parse2 = <$fh2> ) { chomp($parse2); print "$parse1 $parse2\n"; my $wanted = $parse1 . $parse2; my @files = glob "$calls_dir2/*.txt"; printf "Got %d files\n", scalar @files; for my $file (@files) { open my $in_fh, '<', $file; my $basename = fileparse($file); my ($prefix) = $basename =~ /^(.{9})/; my $rnumber = rand(1999); print $prefix, "\n"; my @matches; while (<$in_fh>) { #push @matches, $_ if /^.*?(?:\b|_)$parse1(?:\b|_).*?(?:\b|_)$parse2(?:\b|_).*?$/m; push @matches, $_ if /^.*?(?:|_)$parse1(?:|_).*?(?:|_)$parse2(?:|_).*?$/m; #push @matches, $_ if m/^($parse1)$/i; #push @matches, $_ if m/^'$parse1'$/i; #m/^yes$/i } if ( scalar @matches ) { make_path($parsed_dir); open my $out_fh, '>', "$parsed_dir/${basename}.$wanted.$rnumber.txt" or die $!; $out_fh->autoflush(1); print $out_fh $_ for @matches; print "$out_fh \n"; close $out_fh; } } } }