Your first line contains the * character. You use the data itself as a regular expression when you try to delete the line, but at that point the asterix is interpreted as a regexp metacharacter. The data does not match /....marks_pabs * 4211..../, because that essentially means ".....marks_pabs, one or more spaces, then 4211". (1)

Why are you using a regular expression s/// at all to delete the line? You already know exactly what you want to put there, and you want to override the whole $element. So simply assign an empty string.

From a broader view, though, you shouldn't be slurping the whole file to @ARRAY. That's not scalable. You can read the file line by line and write to a temporary file, eventually copying that over to the original. Or, if you want to edit in-place, check out Tie::File.

(1) Update: to clarify, an asterix means just *zero* or more times, but / * / means zero or more spaces, then another space.


In reply to Re: bewildering array element problem by gaal
in thread bewildering array element problem by Anonymous Monk

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.