my $i = (0 .. 13005);

That's where your problems start; the code is not doing what you expect. Using 0 .. 13005 in scalar context is not a range, but a flip flop, so $i now contains 1. Surprise, surprise.

if ($probe_ID =~ m/$probe_name[$i]/) #match the current entry with the list of probe names

Consequently this doesn't do what you want it to - it just checks against $probe_name[1], not all the probe names.

One approach is to build a regex instead:

# afater the first loop: my $probes_regex = join '|', @probe_name; # you don't need to store all lines in @line, it only wastes memory while (my $line = <DATA>) { my @data = split /\t/, $line; if ($data[0] =~ $probes_regex) { print OUT "$gene[$i]\t$line\n"; } else { print "no match\n"; } }

But if you don't want or need regex matches, but rather exact matches, a hash is much more efficient.

In general it pays off if you tell us about how your data looks like, there might be ways to speed up or simplify the process quite a bit.

Perl 6 - links to (nearly) everything that is Perl 6.

In reply to Re: Match within array by moritz
in thread Match within array by Perl_girl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.