Why don't you try them?
use Benchmark 'timethese'; sub eq_alone { $_[0] eq 'cr' || $_[0] eq 'CR'; } sub lc_eq { lc($_[0]) eq 'cr'; } sub regex { $_[0] =~ /^cr$/i; } timethese (2_000_000, { eq_alone => sub { eq_alone('cr'); eq_alone('CR'); }, lc_eq => sub { lc_eq('cr'); lc_eq('CR'); }, regex => sub { regex('cr'); regex('CR'); }, }); __END__ Benchmark: timing 2000000 iterations of eq_alone, lc_eq, regex... eq_alone: 22 secs (21.48 usr 0.00 sys = 21.48 cpu) lc_eq: 22 secs (22.76 usr 0.00 sys = 22.76 cpu) regex: 25 secs (24.88 usr 0.00 sys = 24.88 cpu)
In short, using lc is roughly just as expensive as a simple 'eq', giving us the same results as doing a double 'eq'. Using a regex adds only a few seconds.

In many cases like this (where the numbers are so close), performance matters less than readability. Use whatever is easier for you to comprehend and easiest for future maintainers to read. I usually vote for using lc in cases like this.


In reply to Re: Function speeds: lc() vs. eq vs. =~ by Fastolfe
in thread Function speeds: lc() vs. eq vs. =~ by Clownburner

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.