use warnings; use strict; my @repls = ( [ qr/pat(\d+)/, 'qq{repl$1}' ], ); my $txt = <<'EOF'; This is some example (pat42) text EOF foreach my $r (@repls) { $txt =~ s/$r->[0]/$r->[1]/eeg; } print $txt; __END__ This is some example (repl42) text