in reply to Re^4: Comparing pattern
in thread Comparing pattern

only first pattern found is displayed now. That's not a problem, but I'd also like to know how to display all patterns if a file contains more than one.

That's easy -- instead of using an "if" statement like this:

if (/($regex_string)/is) {
just use a while loop like this -- making sure to add the "g" modifier (and while I'm at it, I'll add some clarification to the output):
while (/$regex_string)/isg) { print "\nmatched in $arg1:\n==$1==\n"; }
As for your other issue:

$1 will show all wildcarded text between part1 and part2 and not only the pattern part1.*part2 as it should.

What makes you think it "should" display the string "part1.*part2"? When using the capture variables ($1, $2, ...), the normal situation is to want the actual (complete, literal) string that matched the regex, rather than the regex string with its wildcards.

If you want the wildcard-enabled regexes in your list to return a specific constant string, you'll probably want to include that string in your regex list file, store those replacement strings with their regexes in a separate hash, and add some logic in the while loop shown above that will replace any given matching string with the appropriate constant replacement string. Here's an adapted version the three files involved:

First, the regex pattern list -- I'm using a tab character as a field delimiter between the "regex" column (on left) and the "constant-replacement" column (on the right). Trust me, this is the easiest way to get what you want:
part1.*?part2 part1.*?part2 Foo bar Other pattern
Here's a slightly more elaborate test file:
hghghgghghh part1 fff part2 blah blah Foo bar more noise Other pattern another match for part1 stuff I don't want to see part2 blabla
And here's the updated code:
#!/usr/bin/perl -w use strict; my $patterns = "patterns.txt"; my $arg1 = shift; my $regex_string = ''; my %patterns; open (PAT, '<', $patterns) or die "$patterns: $!\n"; while (<PAT>) { chomp; my ( $pattern, $replace ) = split '\t'; $patterns{$pattern} = $replace if ( $replace ); $regex_string .= $pattern . '|'; } close(PAT); chop $regex_string; # remove string-final '|'; open( FILE, "<", "$arg1") or die "$arg1: $!\n"; $_ = do { local $/; <FILE> }; close(FILE); while ( /($regex_string)/gis ) { my $match = $1; for my $replc ( keys %patterns ) { last if ( $match =~ s/$replc/$patterns{$replc}/is ); } print "\nmatched in $arg1:\n==$match==\n"; }