As for hippo, your first case of "^audit" works for me. Could you show the contents of @dir_files using Data::Dumper?

In the second case, note that "\Aaudit" produces the warning "Unrecognized escape \A passed through" (you have warnings turned on, right?). This is because in a double-quoted string, \A doesn't have a meaning. In general, this can be fixed by using qr// to precompile your regexes, as in my $pattern = qr/\Aaudit/;.

However, since you say this is user input, if the user is inputting \Aaudit, then your string will actually be "\\Aaudit" in Perl syntax, which should work, but if it's not, you need to show us code that is more representative of what you're doing for us to be able to see what's wrong, otherwise we're just guessing.

For example, are you chomping your user's input? Use Data::Dumper with $Data::Dumper::Useqq=1; to look at $pattern (and show us that, too).


In reply to Re: Perl Regex \A or ^ Not Working by haukex
in thread Perl Regex \A or ^ Not Working by thundercat

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.