in reply to Find the boundaries of a substring in a string

Take a look at pos.

$ perl -e ' my $str = "BaBBaBBBaBBBB"; # start pos: 0 2 5 9 # end pos: 0 3 7 12 my $fmt = "%d -> %2d\n"; while ($str =~ /(B+)/g) { my $len = length $1; my $pos = pos $str; printf $fmt, $pos-$len, $pos-1; } ' 0 -> 0 2 -> 3 5 -> 7 9 -> 12

Edit: s/look as pos/look at pos/ Thanks LanX.

— Ken