#!/usr/bin/perl use warnings; my $source = shift @ARGV; my $destination = shift @ARGV; my $matchfile=shift @ARGV; open(OUT, '>', $destination) or die $!; open(MF, '<', $matchfile) or die $; while() { @DATA=split(/ /,$_); $matcher=$DATA[0]; $replacer=$DATA[1]; open(IN, '<', $source) or die $!; while() { if($_=~/^$matcher/) { if(s /legend/$replacer/) { print OUT $_; } } else { print OUT $_; } } } close IN; close OUT; close MF;