#!/usr/bin/perl -w use strict; our $input = shift @ARGV; our @books = @ARGV; @ARGV=($input); while (<>) { if (m{^\<\!-- book-\*\s} .. m{\s--\>\s*$}) { if (m{\[delete\]}) { next; } elsif (m{BOOK}) { my $orig = $_; foreach my $book (@books) { $_ = $orig; s{\bBOOK\b}{$book}g; print; } next; } } print; }