>perl -wMstrict -le "my $string=\"AAABBBCCCCDDDEEEFFFGGGHHHIII\"; my @patterns=('BBB','DDD'); my @index; foreach(@patterns){ while($string=~m/\G([A-Z]{3})+?$_/g){ push(@index,$-[2]); pos($string)=$-[2]; print 0+@index; ; } } " 1 2 3 4 5 ... Terminating on signal SIGINT(2)