$search = qr/pattern/; #### s/$search/replace/g; #### my $rep = sub { $_[0] =~ s/a/b/g }; my $string = "abc"; $rep->($string); print "$string\n";