#!/usr/bin/perl # name all dt elements and compile a table of contents based on them my @doc = (); my @arr = (); while(){ if( m/]*)?>([^<]*)<\/dt>/ ){ push(@arr, "
  • $2
  • "); s/$2/$2/; } # handles indentation within the table of contents if( m/]*))?>/ ) { push(@arr,"
    1. "); } if( m/<\/dl>/ ) { push(@arr,"
  • "); } push(@doc,$_); } my $tocElements = ""; foreach(@arr){ $tocElements .= "$_\n"; } my $toc = <Table of Contents
      $tocElements
    END foreach(@doc){ s//$toc/; print $_; }