#!/usr/bin/perl use strict; use warnings; my @STARTPOS = (); my @ENDPOS = (); my $str = "BaaaaBBBBBBaaaaaaaBBBBBBBBBBBBBBBBBBBBaaaBBBBBBBBBBBxB"; print "$str\n\n"; my $i = 0; while (($i = index($str, 'B', $i)) >= 0) { push(@STARTPOS, $i++); while (vec($str, $i++, 8) == 66) {} push(@ENDPOS, $i-1); } # Display results: for (my $i = 0; $i < @STARTPOS; $i++) { print "\nstart: ", $STARTPOS[$i], "\t-> end: ", $ENDPOS[$i]; }