use strict; use warnings; my $string = "aaaaaaaaa"; my $modifiers = "g"; eval "\$string =~ s/a/b/$modifiers;"; print $string;