in reply to regex search fails

Change the line in the loop to

print if /\Q$pattern\E/;

This is equivalent to $pattern= quotemeata($pattern); before the loop. The '$' in your pattern is interpreted as special char in your regex, thats why it isn't working

Replies are listed 'Best First'.
Re^2: regex search fails
by ikegami (Patriarch) on Mar 12, 2009 at 15:09 UTC
    If the "solution" is
    print if /\Q$pattern\E/;
    then $pattern doesn't contains a regexp pattern as its name implies. The variable should be renamed
    my $search_str = $1; ... print if /\Q$search_str/;
    or quotemeta should be called earlier.
    my $pattern = quotemeta($1); # aka "\Q$1" ... print if /$pattern/;