in reply to Re^2: Performance Question
in thread Performance Question

If you want to only swap in values that exist then use the following:
s{(<\?--(\w+)-->)}{ defined($swap{$2}) ? $swap{$2} : $1 }eg;

That will only replace values that match have a corresponding entry in %swap.

If you are brave you can use something like this:
s/<\?--(\w+)-->(??{ defined($swap{$^N}) ? '(?=)' : '(?!)' })/$swap{$1} +/g;

It also does what you are looking for - but without the e modifier on the swap. You will probably need to read perlre to follow it fully - but essentially you are using the (??{}) block to check your regex as you go and then using ?= and ?! to report success or failure.

my @a=qw(random brilliant braindead); print $a[rand(@a)];