my @matches = $str =~ /(\w+)-(\w+|[0-9]+):(\w+|[0-9]+)\s[&|\|](\w+)-(\w+|[0-9]+):(\w+|[0-9]+)\s[&|\|]/g;
This doesn't address the basic problem set out in your OP, but here are a few notes about the regex quoted therefrom:
-
(\w+|[0-9]+) Because [0-9] is a subset of the \w character class, and because the \w term is first in the ordered alternation, this regex expression is exactly equivalent to (\w+) (see Character Classes and other Special Escapes in perlre);
-
[&|\|] The | alternation metacharacter has no special meaning in a character class, nor do any of the other "standard" metacharacters, so this expression is exactly equivalent to [&|] (there are metacharacters specific to character classes; see Using character classes in perlretut);
-
[&|\|] This expression appears twice in the quoted regex. Whenever I see repetition, I think refactor. This could be defined once as
my $sep = qr{ [&|] }xms;
and interpolated as needed, and if it ever needs to change, you only need to worry about changing it in one place (DRY);
-
Take a little whitespace for thy eyes' sake: get to know and love the /x modifier (see regex modifiers in perlre).
All this allows you to rewrite the original
my @matches = $str =~ /(\w+)-(\w+|[0-9]+):(\w+|[0-9]+)\s[&|\|](\w+)-(\w+|[0-9]+):(\w+|[0-9]+)\s[&|\|]/g;
statement as the considerably less eye-bezoggling (IMHO)
my $sep = qr{ [&|] }xms;
my @matches = $str =~ /(\w+) - (\w+) : (\w+) \s $sep (\w+) - (\w+) : (\w+) \s $sep/xg;
Again, this doesn't actually fix the original problem, but at least it becomes easier to see the problem (again, IMHO).
Give a man a fish: <%-{-{-{-<