in reply to Re^4: Find the boundaries of a substring in a string
in thread Find the boundaries of a substring in a string
In that case, subtract 1 from the end value and you are good to go:
use strict; use warnings; my $seq = 'dddddddddBBBBBBBBBBBBDDDDDDDDBBBBBBBBBBBBBBddddddddddddddddddddBBBB +BBBBBBBBBBDDBBBBBBBBddddddddddddd'; while ($seq =~ /(B+)/g) { my $seg = $1; my $seg_length = length ($seg); my $seg_end = pos ($seq) - 1; my $seg_start = $seg_end - $seg_length + 1; print $seg. "|" . $seg_start . "-" . $seg_end . "\n"; }
$ perl 11153140.pl BBBBBBBBBBBB|9-20 BBBBBBBBBBBBBB|29-42 BBBBBBBBBBBBBB|63-76 BBBBBBBB|79-86 $
🦛
|
---|