in reply to text parsing question

REGEX WITH WILDCARD DELIMITER
41 seconds, 1,000,000 iterations
my @nums; push @nums, pos() - 1 while m/-[^-]/g;
REGEX WITH SPACE DELIMITER
16 seconds, 1,000,000 iterations
my @nums; push @nums, pos() - 1 while m/- /g;
SUBSTR WITH SPACE DELIMITER
13 seconds, 1,000,000 iterations
my (@nums, $pos); push @nums, $pos while $pos = index($_, '- ', $pos) + 1;
Note that all of the above have to have a space added to the end beforehand, and also removed afterwards if you intend to use the line for anything else:
$_ = ' ---------- ------------------------- -------- ---- ------ +------------------- ----- ---- ----------- -----------'; $_ .= ' '; my (@nums, $pos); push @nums, $pos while $pos = index($_, '- ', $pos) + 1; print join(' ', @nums); chop;