while ($seq{$k} =~ /(([QGYN]) ((?!\2)[QGYN]|\2(?!\2)) ((?!\3)[QGYN]|\3(?!\3)) (?:((?!\4)[QGYN]|\4(?!\4)) (?:((?!\5)[QGYN]|\5(?!\5)) [QGYN]?)?)?) /xg) { print "\n$k"; print $1." begins at position ", (pos($seq{$k})-length($s)) , "\n"; }