Less example data would have been better, less scrolling to do ;-)

Also please use 'use warnings' and 'use strict'

One error I can see is in this line: @storage = $second_num; In short, the line does nothing sensible, even prevents the array from getting filled and should be removed completely.

Another problem: my ($first, $second) = split(/^\s{1}/, $organized); Using '^' in a split would only make sense if you wanted to split a file into separate lines (you also would need the regex-modifier m). But since you want to split one line, '^' makes this line simply a no-op. Also "\s{1}" is identical to "\s". So you could just write "split(/\s/, ..."

@final_storage seems superfluous, but in case you need it, copying the array would be as easy as @final_storage= @storage;

Finally, all this stuff you are doing step by step could be done by a simple regex if it is guaranteed that all elements except the first one have a space before them:

while (my $organized = <DATA2>) { $organized=~s/(\s)\w+/$1z/g; print $organized; }

UPDATE: Thanks to jwkrahn for noticing that \s in the replacement isn't really working. Changed to use parentheses and $1


In reply to Re: regular expessions question: (replacing words) by jethro
in thread regular expessions question: (replacing words) by $new_guy

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.