http://www.perlmonks.org?node_id=350050


in reply to Re: Re: Returning regexp pattern that was used to match
in thread Returning regexp pattern that was used to match

If you are concerned about speed than contrive to have precompiled those patterns before testing them. I had you directly testing against the keys in the pattern. Another idea might be to do this.

use vars qw' %CACHED_RX '; sub do_this { my $self = shift; my %rx = %{ shift() }; for ( keys %rx ) { my $rx = $CACHED_RX{$_} ||= qr/$_/; if ( $self->{'find'} =~ $rx ) { } } }