in reply to Handling scalars as regexs within a substitution. (Take 2)

Ha! Got another solution. Using what chromatic previously suggested. I discovered that it is working, but it is ignoring the space in the '$1 ', so the string is not modified. However, if the replacement string is specified as '$1." "', because the /e modifier evalutes it as a Perl expression, it correctly puts the space after the value of $1.

So here's another version that works:

#!/usr/bin/perl my $string="realllylongstringthatrefusestoend <A HREF=\"http://perlmo +nks.org/images/blah/blah/blah\">\n"; print splitter($string,"<.*?>",'(\S{18})','$1." "'); sub splitter{ my($string,$spliton,$find,$replace)=@_; my @array=split(/$spliton/,$string); my $i=0; my @splitters; my $str; while($string=~/($spliton)/g){ push @splitters,$1; } for (@array){ s/$find/$replace/eeg; ; $str.=$array[$i]; $str.=$splitters[$i]; $i++; } $str; }
I believe this has the same security problems as evaluating with double quotes, because it allows the execution of arbitrary perl code.

--ZZamboni