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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |