if ( $seq !~ m/$sub1/ && $seq !~ m/$sub2/ ) { # this means there are at least 2 mismatches # the substring you are looking for is not here # so don't check for any patterns, just "next;" }