http://www.perlmonks.org?node_id=938748


in reply to string match using with an N in any position

If the matching strings are all of the same length:
my %match = map { $_ => 1 } qw(GCGAT CACGT); while (<>) { my $line = $_; s/N//; # remove the first N in the string print "match: $line" if $match{substr($_, 0, 5)} }
otherwise, if they have different lengths:
my $pattern = join('|', qw(GCGAT CACGT)); $pattern = qr/^(?:$pattern)/; while (<>) { my $line = $_; s/N//; # remove the first N in the string print "match: $line" if $_ =~ $pattern; }