in reply to Passing regexp as argument

You are trying to pass a whole substitution expression, not just a regex. You need eval STRING to do what you want, eval "\$nodeName =~ $regEx"; Note the escaped sigil in $nodeName. That is to prevent the variable from having its value interpolated before evaluation.

I'd be inclined to pass the regex and substitution as two arguments and interpolate them

sub changeNodeNames { my ($self,$node,$regEx,$subst) = @_; my $nodeName = $node->nodeName; $nodeName =~ s/$regEx/$subst/; # . . . } $foo->changeNodeNames($anode, qr/foo/, 'bar');

After Compline,
Zaxo