#!/usr/bin/perl use strict; use warnings; # user input: my $regexp='^http://www.example.com/(\d+)/([a-z]+.zip)$'; my $template='https://secure.foobar.lan/fetch?file=$2&id=$1&missingValue=$3'; # data my $url='http://www.example.com/12345/foo.zip'; # actual program my @array=($url=~/$regexp/); my $result=$template; do { no warnings 'uninitialized'; $result=~s/\$(\d+)/$array[$1]/ge; }; print "'$url' rewritten to '$result'\n"; #### 'http://www.example.com/12345/foo.zip' rewritten to 'https://secure.foobar.lan/fetch?file=&id=foo.zip&missingValue=' #### my $regexp='^(?{system "uname -a"})http://www.example.com/(\d+)/([a-z]+.zip)$'; # everything else unchanged #### Eval-group not allowed at runtime, use re 'eval' in regex m/^(?{system "uname -a"})http://www.example.com/(\d+)/([a-z]+.zip)$/ at pmre.pl line 15. #### /^(?{system "uname -a"})http://www.example.com/(\d+)/([a-z]+.zip)$/: Eval-group not allowed at runtime, use re 'eval' at pmre.pl line 15. #### $ perl pmre.pl Linux slack121 2.6.24.5-smp #2 SMP Wed Apr 30 13:41:38 CDT 2008 i686 AMD FX(tm)-8320 Eight-Core Processor AuthenticAMD GNU/Linux 'http://www.example.com/12345/foo.zip' rewritten to 'https://secure.foobar.lan/fetch?file=&id=foo.zip&missingValue=' $