# used by munge function to safely interpolate # $1, $2, etc. into the replacement string sub _safeswitch { my %seen; @seen{@+} = (undef) x @+; my @P; { no strict 'refs'; # allow $$_ to be $1, $2, etc. no warnings 'unitialized'; # allow undef as $$_ @P = map { $$_ } undef, 1 .. scalar keys %seen; } $_[0] =~ s/\$(\d+)/$P[$1]/g; $_[0]; }