#!/usr/bin/perl use strict; my $string = 'YYSFTVMETDPVN[115]HMVGV' . 'ISVEGRPGLFWFN[115]ISGGDK'; my @pos; my $test = 'N[115]'; for ( my $i = 0; $i < length( $string ); $i++ ) { push( @pos, $i ) if ( substr( $string, $i, 6 ) eq $test ); } @pos = map { $_ == 0 ? $pos[$_] : $pos[$_] - 5 } (0 .. $#pos ); print "Found N at positions: ". join( ', ', @pos ), "\n";