in reply to Pattern matching

Try this:
$single = "12"; @allbonds = qw(12 13 123 12,45 123,45 12,345 1234 12345); @somebonds = grep /^$single(?:\d|,\d{2})$/o, @allbonds;

Replies are listed 'Best First'.
Re: Re: Pattern matching
by Dogg (Scribe) on Mar 26, 2002 at 00:44 UTC
    Thanks. That works perfectly.
    I've never used grep (I've always made do with simpe matching).
    This will make me learn it.

    Thanks again.

      You're missing the point. It's not that he's using grep, but that he's anchored the match with a $ at the end of the regexp that's important. You were matching more than you thought you should be because you hadn't specified that the regexp had to match the entire string.