use strict; use warnings; my %substitutions = (); while ( ) { chomp; my ($pattern, $replace) = split; my $rxPattern = qr{(?si)$pattern}; $substitutions{$rxPattern} = $replace; } my $str = q{a capital M and Fish}; print qq{$str\n}; $str =~ s{$_}{$substitutions{$_}} for keys %substitutions; print qq{$str\n}; __END__ \s*M\s* MALE \s*F\s* FEMALE