in reply to Pattern Match n00b

Doesn't the ;?? mean match semi-colon 0 or 1 times and be non-greedy?

It does, but it only makes that part of the match non-greedy. The (.+) remains greedy.

But if you make that part non-greedy, then you will be asking to capture as little as possible following the ':', that might or might not be followed by a ';'. Which means it will capture just a single character.

A couple of ways to approach the problem:

  1. Make capture non-greedy and have a definite terminating condition:/$some_variable\:(.+?)(?:;|$)/

    Where (?:;|$) requires a semicolon or the end-of-string, (prefering the former) to terminate the capture.

  2. Or as you know the bit you want to capture cannot contain a ';', reduce the scope of the capture using [^;]+ in place of '.' and omit the terminator.
    /$some_variable\:([^;]+)/

Either works:

$pet_list = 'dog:boston.terrier;cat:orange.tabby';; $pets=[]; $pet_list =~ /$_\:(.+?)(?:;|$)/ and push @{$pets},$1 for qw[cat dog]; print for @{$pets};; orange.tabby boston.terrier $pets=[]; $pet_list =~ /$_\:([^;]+)/ and push @{$pets},$1 for qw[cat dog]; print for @{$pets};; orange.tabby boston.terrier

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."