{ my %orig; sub re_db_on (\$) { my ($r) = @_; die "not a regex" unless ref $$r eq 'Regexp'; return if $orig{$r}; $orig{$r} = $$r; # note this depends on the proper stringification of the regex $$r = eval qq{ use re qw/Debug EXECUTE/; qr/$$r/ }; } sub re_db_off (\$) { my ($r) = @_; return unless $orig{$r}; $$r = delete $orig{$r}; } } my $ra = qr/a/; my $rb = qr/b/; my $rc = qr/c/; my $str = "abc"; $,=", "; $\="\n"; print $str=~$ra, $str=~$rb, $str=~$rc; re_db_on $rb; print $str=~$ra, $str=~$rb, $str=~$rc; re_db_off $rb; print $str=~$ra, $str=~$rb, $str=~$rc;