my @matches = "-$str-" =~ /(?:-[^0-]+)*(?:-0){4,}(?=-)/g;
Useful test cases:
- Pattern is at the beginning of the string: 1-0-0-0-0-2-3-4 (That's why I prepended a "-" to the string.)
- Pattern is at the end of the string: 0-1-0-0-0-0 (That's why I appended a "-" to the string.)
- Two patterns in a row: 1-2-3-0-0-0-0-4-5-6-0-0-0-0 (That's why I used /(?=-)/ instead of /-/ at the end.)
- No leading non-zeroes: 0-0-0-0-1-2-3
Note: My code doesn't find overlapping matches. It's not an issue with the pattern you describe, but it might be for other patterns.