in reply to Need to grep for a string that ends with $$

if ($target =~ /\Q$matchmember\E$/) { print "Match!\n"; }

See perlretut for more information.

Replies are listed 'Best First'.
Re^2: Need to grep for a string that ends with $$
by ikegami (Patriarch) on Mar 07, 2012 at 00:38 UTC

    The OP said that $matchmember ends with $$, not that $target must end with $matchmember.

    That means the "$" shouldn't be there.

    if ($target =~ /\Q$matchmember\E/) { print "Match!\n"; }

    And since the \E is trailing, it can be omitted.

    if ($target =~ /\Q$matchmember/) { print "Match!\n"; }

    Finally, he asked to find all occurrences, so it would be more like:

    my @matches = $target =~ /(\Q$matchmember\E)/g;

    or

    while ($target =~ /(\Q$matchmember\E)/g) { print "Found $1 at $-[1]\n"; }