use strict; use warnings; my @strs = qw(GNNTCGANNTT GAATCGNNNTT GANNCGNNNNN); for my $str (@strs) { my $rstr = reverse $str; my @starts; push @starts, $-[1] while $rstr =~ /(N+)/g; if (1 == @starts) { print "$str: One N found at @starts\n"; } elsif (@starts) { print "$str: Ns found at @starts\n"; } else { print "No N found in $str\n"; } }