#!/usr/bin/perl # reorganize frontmatter use warnings; use strict; use Path::Tiny; use HTML::HTML5::Entities; my $infile = shift; my $outfile = shift || $infile; $_ = path($infile)->slurp_utf8; # swap sections → Copyright, TOC, Foreword, Preface s|^((?:.*?\n)?)(= Preface(?:(?!\n=).)*\n)(= Copyright(?:(?!\n=).)*\n)(= Table(?:(?!\n=).)*\n)(= Foreword(?:(?!\n=).)*\n)(=.*)$|$1$3$4$5$2$6|s; # drop section Copyright s|^((?:.*?\n)?)(= Copyright(?:(?!\n=).)*\n)(=.*)$|$1$3|s; path($outfile)->spew_utf8($_); 1;