#!/usr/bin/perl -w use strict; my $out_file = "out.txt"; my $match_file = "pattern.txt"; my $in_file = "20051208.LOG"; open(my $match_in, '<', $match_file) or die("open failed: $!"); my @matches = <$match_in>; close($match_in); open(my $fh_in, '<', $in_file) or die("open failed: $!"); my @lines = <$fh_in>; close($fh_in); open(OUTFILE, '>>', $out_file) or die("open failed: $!"); foreach my $lines (@lines) { foreach my $matches (@matches) { chomp($matches); my $matchtmp = $matches . ".*SUPSOSODEV" . '|' . $matches . ".*AJTSOSOCFD" . '|' . $matches . ".*AJTSOSOISI" . '|' . $matches . ".*AJTSOSOCLA"; if($lines =~ qr/$matchtmp/) { print OUTFILE; } } close(OUTFILE);