\item Bernoulli measure, 14
\item cellular automata
\subitem Soft, 3, 28
\subitem balance theorem, 23, 45
\item tiles
\subitem tiling problem, 19, 58
\subitem aperiodic tile set, 18, 45
\item Garden-of-Eden -theorem, 12
\item Bernoulli measure, 15, 16, 35
\item cellular automata
\subitem balance theorem, 9, 11, 14
\subitem blocking word, 22, 32
\item Garden-of-Eden -theorem, 32
I have to sort the above index alphabetically using a perl script. Duplicate item or subitem entries should be merged and their numbers should be sorted. The subitems also should be sorted under respective item and their numbers should be also sorted. If same item is repeated in more than one place with subitems all the subitems should be merged under a single item and also subitems should be sorted