The print statement
    print"$config[$t][0]\n";
in the print loop of example (1) of the OP suggests the possibility* you are dealing not with an array of strings, but with an array of array references each of which has at least one element, the first, that is a string.

If this is so, the following code addresses this case, both with more and less redundant, as NetWallah has pointed out, map approaches, and with a more 'standard' for-loop.

>perl -wMstrict -le "my @config = ([ 'fee fie' ], [ 'foe'], [ 'fum' ],); printf qq{'$_->[0]' } for @config; print ''; ;; @config = map { $_->[0] =~ s{(f[eio]e)}{\u$1}xmsg; $_; } @config; printf qq{'$_->[0]' } for @config; print ''; ;; map { $_->[0] =~ s{ (F [eio] e) }{\U$1}xmsg } @config; printf qq{'$_->[0]' } for @config; print ''; ;; for my $ar (@config) { $ar->[0] =~ s{ (F [EIO] E) }{\L$1}xmsg;; } printf qq{'$_->[0]' } for @config; print ''; " 'fee fie' 'foe' 'fum' 'Fee Fie' 'Foe' 'fum' 'FEE FIE' 'FOE' 'fum' 'fee fie' 'foe' 'fum'

* I know this is a possibility because if you had been dealing with an array of simple strings, you would have seen an error or a bunch of warnings because, of course, you're running with strictures and warnings enabled.


In reply to Re: String substitution inside an array by AnomalousMonk
in thread String substitution inside an array by Monkomatic

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.