in reply to Identifying Reverse Position of Specific Character in a String

If you want a regex-only solution:

#!/usr/bin/perl use strict; use warnings; my @strings = qw( GNNTCGANNTT GAATCGNNNTT GANNCGNNNNN ); my @found; for my $string( @strings ){ my $revstring = reverse $string; $revstring =~ m< (?: .*? (?{ [ $^R ? @{ $^R } : () , pos ] }) NN+ )+ (?{ @found = @{ $^R }; }) >x; print "String: $string Positions: ", join( ', ', @found ), "\n"; }

Prints:

String: GNNTCGANNTT Positions: 2, 8 String: GAATCGNNNTT Positions: 2 String: GANNCGNNNNN Positions: 0, 7


--chargrill
$,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}