# add order information to corpus XML document %ordermap = (); $curterm = 1; $minlc = 99; $curid=""; while (<>) { if (($key) = m' with lc="$hval"/> # update $minlc $temp = $ordermap{$key}; s!/>!lc="$temp" />!; print; $minlc = $temp if $temp < $minlc; } elsif (m!!) { # add $minlc to hash for $curid $ordermap{$curid} = $minlc; $minlc = 99; print; } elsif (m!!) { # reset hash %ordermap = (); $curterm = 1; print; } else { print; } }