One way to do this is to capture the junk along with the substrings
This is a fine use for the special treatment of capturing parentheses in the first (regex) argument to split:
my @chunks; my @start_pos; my $pos = 0; foreach my $chunk ( split /(X+)/, $string ) { unless ( $chunk =~ /^X/ ) { push @start_pos, $pos; push @chunks, $chunk; } $pos += length $chunk; }
In reply to Re^2: Split Function - Positions
by tkil
in thread Split Function - Positions
by MiamiGenome
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |