In addition to the problems addressed by others, I think there may be problems with the file name comparison regex in the OP. (Corion's reply Re: Array question also addresses this by using a different regex.)

The regex  $string_A =~ /^$string_B/i is anchored only at the beginning of the string, so if  $string_A eq 'foobar' and  $string_B eq 'foo' the two strings will match. (The strings being compared in the OP seem to consist of a file name and another file name with date appended, so this behavior may be correct.) A complete (case insensitive) match could be achieved by matching with  /^$string_B$/i using the  $ anchor.

Second, and perhaps more important, a string interpolation like  /^$string_B/ causes any regex metacharacters like  . ^ $ ( ) [ ] that are present in the string to be active in the compiled regex. (The most pesky metacharacter in this case is probably  . (dot): match any* character.) The usual practice would be to metaquote the intepolated string in some way, e.g.,  /^\Q$string_B\E/i or with the quotemeta function prior to interpolation.

* Well, any except a newline unless the  //s 'dot matches all' regex modifier is used. See s in the Modifiers section of perlre.


In reply to Re: Array question by AnomalousMonk
in thread Array question by Karger78

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.