Seems like you need to "sub-select" your list. Given that it's not in order, I'd build a hash of arrays (HoA) with the keys corresponding to your selections, then process them in whatever order you wanted.

#!/usr/bin/perl -w use strict; my @array = qw(001.file.a 001.file.b 002.file.a 002.file.b); my %hash; for my $filename (@array){ $filename =~ /^(\d+)/; push @{$hash{$1}}, $filename; } for my $group (sort { $a <=> $b } keys %hash){ print "Processing group '$group':\n"; for my $file (@{$hash{$group}}){ print "\tProcessing $file:\n"; ### Do stuff } }

Update: Wow, you guys are quick. I hit the 'Comment' link, typed out the code, previewed it, and posted it - and suddenly there were three posts ahead of me where there had been zero. I guess I'd better learn to type faster. :) It's also amusing (but unsurprising) that all of us gave essentially the same answer, so I'm going to '++' everyone 'cause they're so brilliant. :)


-- 
Human history becomes more and more a race between education and catastrophe. -- HG Wells

In reply to Re: iterating over array to create smaller arrays based on pattern match by oko1
in thread iterating over array to create smaller arrays based on pattern match by phippsy

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.