in reply to manipulating alignment data

I guess by "not conserved" you mean you're looking for columns that aren't the same in each line. If that's true, this might get you started:
use strict; use warnings; my $first = <DATA>; chomp $first; my $template = ''; while (<DATA>) { chomp; $template |= $first ^ $_; } for (split //, $template) { print ord == 0 ? '.' : 'X'; } print "\n"; __DATA__ ATCG--ATCG-ATCG ATGC--ATCG-ATCG ATGC-A-TCG-ATCG ATGC--ATCG-ATCG ATCG--ATCG-AACG

The output produces a dot for each column where all rows have the same character, and an X for those where there are at least two different characters:

..XX.XX.....X..

If that's not what you want, please make your description more verbose, and include the expected output for your example input.

Replies are listed 'Best First'.
Re^2: manipulating alignment data
by jwkrahn (Abbot) on Mar 28, 2012 at 21:05 UTC
    for (split //, $template) { print ord == 0 ? '.' : 'X'; } print "\n";

    Another way to do that:

    $template =~ tr/\0/X/c; $template =~ tr/\0/./; print "$template\n";

    But this looks like it produces the output the OP wants:

    print "position $-[0] is not conserved\n" while $template =~ /[^\0]/g;
Re^2: manipulating alignment data
by AWallBuilder (Beadle) on Mar 28, 2012 at 11:55 UTC

    thank you.Yes, by conserved I mean columns where there is more than one letter. Could you please explain the following lines more verbosely. Also, I need the position, so I guess in your case instead of printing I could feed it into and array or hash and then print out the positions with an X

    $template |= $first ^ $_;
    print ord == 0 ? '.' : 'X';

      infix ^ is the bitwise XOR operator, so the resulting string from $first ^ $_ has a zero-byte at every position where $first and $_ are equal.

      Likewise | is the bitwise OR operator, so $template accumulates non-zero bytes at any character position where any row differed from $first.

      print ord == 0 ? '.' : 'X';

      ord == 0 simply checks if $_ is the zero-byte. If yes, a dot is returned, otherwise an X.

      For more information look into perlop, search for "bitwise" and "ternary".