How to use a variable as modifier in a substitution
问题 Is there a way to use a variable as modifier in a substitution? my $search = 'looking'; my $replace = '"find: $1 ="'; my $modifier = 'ee'; s/$search/$replace/$modifier; I need to use an array of hashes to make bulk search-replace with different modifiers. 回答1: Hm, if I had to do it I would do like this: use warnings; use strict; my @stuff = ( { search => "this", replace => "that", modifier => "g", }, { search => "ono", replace => "wendy", modifier => "i", } ); $_ = "this ono boo this\n"; for