Here is another version using the arrays as listed in OP and a reference that loops through each array. You could add logic to break out of the loops once the value is found.

Updated again... left out $found declaration and initialization (fat fingers).

#!c:\perl\bin\perl.exe use strict; use warnings; my @lane01_1 = (200900..202543); my @lane01_2 = (202544..204187); my @lane01_3 = (204188..205831); my @lane01_4 = (205832..207475); my @lane01_5 = (207476..210119); my @lane01_6 = (210120..211763); my @lane01_7 = (211764..213407); my @lane01_8 = (213408..215051); my $arrayref; my $buildvar; my $vector = 209456; my $found = 0; while(! $found) { $buildvar = "\\\@" . "lane01_" . $i; $arrayref = eval($buildvar); if(! defined @$arrayref) { print("vector: $vector not found\n"); last; } for(my $j = 0; $j < (scalar(@$arrayref)); $j++) { if($$arrayref[$j] == $vector) { print("lane # is $i\n"); $found = 1; } } $i++; } OUTPUT: lane # is 5

Update #1: Removed some values from testing

Update #2: Included output.

Update #3: Couldn't take it - replaced outer for loop with a while loop and a bool. This also required a test to make sure @$arrayref references a valid array. If it's not, then there is no match for $vector. Original for loop included below.

for (my $i = 1; $i <= 8; $i++) { $buildvar = "\\\@" . "lane01_" . $i; $arrayref = eval($buildvar); for(my $j = 0; $j < (scalar(@$arrayref)); $j++) { if($$arrayref[$j] == $vector) { print("lane # is $i\n"); } } }

In reply to Re: match with elements in array by dineed
in thread match with elements in array by finder003

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.