The T* part of that restricts the match to files beginning with "AB DA" followed by 0 or more T's followed by ".doc" and that's probably not what you meant. You are missing a dot. Try /^AB DAT.*\.doc$/i instead. Note that I replace the \s with a literal space. That's because \s will also match a tab or a newline.

I don't know if you really want the /i modifier. That will make the expression case insensitive so it will also match files beginning with "ab dat" or "Ab DaT" and so on.

You might also consider using unless rather than if ... !~ too. I'd write the whole thing as

next unless $file =~ /^AB DAT.*\.doc$/;

By the way, filenames with spaces in them are yucky. If you have control over the filenames, I suggest renaming them and replacing spaces with underscores.

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Reg Expression on file name by sauoq
in thread Reg Expression on file name 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.