#! perl -slw use strict; my $polar = 'DEHAW'; # Uniq E my $charged = 'DGYAH'; # Uniq Y my $hydphb = 'GAFIVL'; # Uniq FIVL my $re_seq = qr[ # Capture ( # start char [$polar$charged] # Must contain motif (?= .* H[$hydphb][$polar][$hydphb]W .* ) # Mustn't contain more than 4 polar chars (?! (?: .* [$polar] ){5} ) # 18-24 polar|hydphb chars # Excludes the start and end chars (Adjust if wrong!) [$polar$hydphb]{18,24} # # end char [$polar$charged] ) ]x; while( ) { chomp; print "\nTesting '$_'"; s[\s+#.*$][]; print "matched: '$1'" while m[$re_seq]g; } __DATA__ YVVVVVVVVVVHVEVWVVY # 1 too short YVVVVVVVVVVHVEVWVVVY # min match YVVVVVVVVVVHVEVWVVVVVVVVVY # max match YVVVVVVVVVVHVEVWVVVVVVVVVVY # 1 too long YVVVVVVVVVVHVEVWVVVVVVVVEY # max polar YVVVVVVVVVVHVEVWVVVVVVVEEY # too many polar YVVVVVVVVVVHVYVWVVVY # missing motif #### P:\test>junk Testing 'YVVVVVVVVVVHVEVWVVY # 1 too short' Testing 'YVVVVVVVVVVHVEVWVVVY # min match' matched: 'YVVVVVVVVVVHVEVWVVVY' Testing 'YVVVVVVVVVVHVEVWVVVVVVVVVY # max match' matched: 'YVVVVVVVVVVHVEVWVVVVVVVVVY' Testing 'YVVVVVVVVVVHVEVWVVVVVVVVVVY # 1 too long' Testing 'YVVVVVVVVVVHVEVWVVVVVVVVEY # max polar' matched: 'YVVVVVVVVVVHVEVWVVVVVVVVEY' Testing 'YVVVVVVVVVVHVEVWVVVVVVVEEY # too many polar' Testing 'YVVVVVVVVVVHVYVWVVVY # missing motif'