#!/usr/bin/perl while (<>) { chomp; ($ref, $text) = split (/\t/); if ($text) { ($chap, $xxx, $par, $s) = split (/\|/, $ref); $chap+=0; $par+=0; $s+=0; $ref=~s/\|/./g; $ref="id.$ref"; if ($chap != $oldchap) { $work.="

\n

$text "; $oldchap=$chap; $oldpar=$par; } elsif ($par != $oldpar) { $work.="

\n

$text "; $oldpar=$par; } else { $work.="$text "; } } } $head = "

"; $tail ="

"; print "$head$work$tail";