#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=766743 use warnings; my %thexor; # check for N mismatches different from non-N mismatches for my $x ( qw( A T G C N ) ) { for my $y ( qw( A T G C N ) ) { $x lt $y and $thexor{$x ^ $y} .= "$x$y "; } } use Data::Dump 'dd', 'pp'; dd \%thexor; # yes they are # mismatch "\2\4\6\23\25\27" # match "\0\t\r\17\32" local $/ = ''; while( ) { my ($x, $y) = split; my $bad = ($x ^ $y) =~ tr/\2\4\6\23\25\27//; # therefore this counts mismatches print "$x ^ $y => ", pp($x ^ $y), $bad ? ' FAIL' : ' ok', "\n"; } __DATA__ ATGNCNC ATGACNN ATGNCNC TTGNNNC