use Regexp::Assemble; my $patterns = "/path/to/file.txt"; my $list_regex = Regexp::Assemble->new(file => $patterns); $list_regex->track( 1 ); open( FILE, "<", "$arg1") or die "$arg1: $!\n"; while () { if (/$list_regex/) {print "\n$arg1\n$list_regex->matched\n";} } close(FILE); } #### my $patterns = "/path/to/file.txt"; my $arg1 = shift; open( PATTERNS, "<", $patterns ) or die "$patterns: $!\n"; my @list_patterns = ; close PATTERNS; chomp @list_patterns; my $regexStr = "(" . join("|", @list_patterns) . ")"; my $list_regex = qr{$regexStr}i; open( FILE, "<", "$arg1") or die "$arg1: $!\n"; while () { if (/$list_regex/) {print "\n$arg1\n$1\n";} } close(FILE); #### part1.*part2 #### fggffgfg part1 hghggh ghhggh hggh part2 ytyty