#!/usr/local/bin/perl
use strict;
use warnings;
use String::Interpolate qw(safe_interpolate);
# Read the regexes
my @Rexes;
while (my $t = <DATA>) {
chomp $t;
last if $t =~ /^$/;
my ($regex, $repl) = split /\t+/, $t;
push @Rexes, [ qr($regex), $repl ];
}
# Process the text
while (my $l = <DATA>) {
$l=~ s/$$_[0]/safe_interpolate($$_[1])/eg for @Rexes;
print $l, "\n";
}
__DATA__
duck cluck
a(b+)c \uc${1}\ua
That bird says "duck!"
xyzzy plugh ac abc abbc abbbc
That bird says "cluck!"
xyzzy plugh ac CbA CbbA CbbbA