another approach, with a few printing examples, also realize that something like $critters[1][2] is valid also.
#!/usr/bin/perl -w use strict; use Data::Dumper; #I made the 2D array bigger as you only had one row my @critters = ( ['a sheep', 'an elephant', 'the wolf'], ['a fish', 'an eel', 'the whale'] ); print "original array\n"; print Dumper \@critters; my @articleList = ('the', 'an', 'a'); my $articleregex = join("|", @articleList); print "one way to access the whale and a sheep\n"; print "$critters[1][2], $critters[0][0]\n"; #the whale a sheep foreach my $rowref (@critters) #each row { foreach my $name (@$rowref) #each "column" in that row { $name =~ s/^($articleregex) //; } } print "\nmodified array:\n"; print Dumper \@critters; print "\nPrint one row\n"; #when derefencing a thing with a subscript, you need to #use {} to make clear what is being dereferenced, i.e. the #entire row print "@{$critters[1]}\n"; my $ref2arow = $critters[1]; #using an reference to a row print "$ref2arow->[1]\n"; #print 2nd column (eel) __END__ original array $VAR1 = [ [ 'a sheep', 'an elephant', 'the wolf' ], [ 'a fish', 'an eel', 'the whale' ] ]; one way to access the whale and a sheep the whale, a sheep modified array: $VAR1 = [ [ 'sheep', 'elephant', 'wolf' ], [ 'fish', 'eel', 'whale' ] ]; Print one row fish eel whale eel
Try adding prints in various places and play with this.

In reply to Re: 2d arrays and 'Can't use string as an ARRAY ref' by Marshall
in thread 2d arrays and 'Can't use string as an ARRAY ref' by ronlewis

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.