in reply to Why is "any" slow in this case?

Generally speaking: Sub routines and iteration are slower than operations. So ugly is always going to be faster than any, unless the ugly operation gets absurdly large, probably 100's of numbers.

Secondly, every time you access $1 or $2, there is a check of the regexp context, its not just taking some already known value, which adds overhead. So _cr of assigning $1/$2 to a local variable should always end up faster compared to even 2 or 3 uses of $1/$2.

Replies are listed 'Best First'.
Re^2: Why is "any" slow in this case?
by LanX (Saint) on Jul 28, 2025 at 08:40 UTC
    > every time you access $1 or $2, there is a check of the regexp context,

    Could you please elaborate what this means, especially "regexp context"?

    It rings a bell, but this seems counter-intuitive with a read only value like $1.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      If you use $1 and then Devel::Peek::Dump it, you will see the values you got stored in it, but that's all ephemeral; the next access will trigger the get magic again, which does a lot of work to get info from where the regex engine stashes it (and leaves it in the $1 SV so the remainder of that operation can use it).