<?xml version="1.0" encoding="windows-1252"?>
<node id="991225" title="Re: filtering an array" created="2012-09-01 21:50:23" updated="2012-09-01 21:50:23">
<type id="11">
note</type>
<author id="352046">
ww</author>
<data>
<field name="doctext">
Alternate approach (with a little error checking, which I hope is so basic and transparent as to need no explanation):

&lt;p&gt;You might want to upend your thought process.  Simply warn about any elements of your data that have "G" or "T" (and, as you'll see in the code below, any non-conforming data -- letters other'n ACTG; too many or few  letters, etc.) and then &lt;c&gt;next&lt;/c&gt; past them without saving.  Save the desired elements (the digits) to your @positions array, only after substituting away any combinations of "A" and "C" and -- when you've processed all the data, spit out the positions that satisfy your criteria:&lt;/p&gt;

&lt;c&gt;#!/usr/bin/perl
use 5.014;
# 991184

my @positions;
my @data = ('1 ACAC',
            '2 AGAC',
            '3 AGTC',
            '4 ACCA',
            '5 DUMMY',
            '6 ACAATG',
            '7 CAAC',
            '8 acaacc',
            '9 aca ',
            );

for my $data(@data) {
    if ( $data =~ /[GT]/ || $data =~ /[^[ACTG]{4}$/) {
        say "Data ERROR or contains G or T ( $data )";
        next;
    } elsif ( $data =~  /^\d+ [AC]{4}$/i ) { # too many; too few? covered here
            $data =~ s/ [AC]{4}//i;
            chomp $data;
            push @positions, $data;
    } else {
            say "Problem with data? $data";
    }
}

print "\n Good data at positions: ";
for my $position (@positions) {
    print "$position ";          # depending on size of valid positions, you may 
}                                # want to stack them vertically --
                                 # simply replace the 'print' with 'say'
say "\n Done";
&lt;/c&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;c&gt;C:\ 991184.pl
Data ERROR or contains G or T ( 2 AGAC )
Data ERROR or contains G or T ( 3 AGTC )
Data ERROR or contains G or T ( 5 DUMMY )
Data ERROR or contains G or T ( 6 ACAATG )
Data ERROR or contains G or T ( 8 acaacc )
Data ERROR or contains G or T ( 9 aca  )

 Good data at positions: 1 4 7
 Done&lt;/c&gt;

&lt;p&gt;Done in babytalk, to some extent, to ensure clarity. Compare OP's questions about the Monks' responses, above.&lt;/p&gt;</field>
<field name="root_node">
991184</field>
<field name="parent_node">
991184</field>
</data>
</node>
