in reply to Compare two variables

This will count the matching characters.
my $orig = <DATA>; my $i = 0; while (<DATA>) { my $matches = $orig ^ $_; printf "Sequence %d has %d identities\n", $i++, $matches =~ tr/\0/ +/; } __DATA__ ATCGGGACG TCGTCAGCG ATGCGAAAA
Prints:
Sequence 0 has 2 identities Sequence 1 has 4 identities

Replies are listed 'Best First'.
Re^2: Compare two variables
by dmunoze (Initiate) on May 20, 2014 at 00:17 UTC

    Thanks for the answer, but I didn't understand the line with DATA. I mean, what exactly DATA contains?

      Here's essentially the same thing without __DATA__:

      c:\@Work\Perl\monks>perl -wMstrict -le "my $seq = 'ATCGGGACG'; my $n = 0; ;; for my $s (qw(TCGTCAGCG ATGCGAAAA TTTTTTTTT TATTTTTTT)) { print qq{\n'$seq' original}; my $idents = (my $same = $s ^ $seq) =~ tr/\x00//; $same =~ tr/\x00-\xff/^ /; print qq{'$s' seq }, $n++; print qq{ $same $idents identities}; } " 'ATCGGGACG' original 'TCGTCAGCG' seq 0 ^^ 2 identities 'ATCGGGACG' original 'ATGCGAAAA' seq 1 ^^ ^ ^ 4 identities 'ATCGGGACG' original 'TTTTTTTTT' seq 2 ^ 1 identities 'ATCGGGACG' original 'TATTTTTTT' seq 3 0 identities