my $digit = '\d'; /$digit/; only compiles a regexp once as well.
Perhaps, but that's not the OP's usage.
my $digit = qr/\d/; foo($digit); # Compiles once my $digit = '\\d'; foo($digit); # Compiles any number of times
Whether or not passing a pattern as a compile regexp or as string is faster depend on what the subroutine is doing with it.
I said that in the post to which you are replying.
In reply to Re^4: passing regular expression
by ikegami
in thread passing regular expression
by karthikasasanka
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |