use strict; use warnings; my $string='YYSFTVMETDPVN[115]HMVGVISVEGRPGLFWFN[115]ISGGDKN[115]'; my $offset = 0; my $substring = 'N[115]'; my @positions; while (1) { my $pos = index($string, $substring, $offset); last if $pos < 0; $offset = $pos + length($substring); $pos -= 5 * @positions; push @positions,$pos; } print "Positions: @positions\n"; #### Positions: 12 30 37