I have some code that can reads text from a FAQ webpage and stores the sentences in an array. I need to group the Q/A pairs somehow. They will then all be written to a *.aiml output file in the format below

<aiml>
<category>
<pattern>WHAT ARE YOU</pattern>
<template>
I am the latest result in artificial intelligence,
which can reproduce the capabilities of the human brain
with greater speed and accuracy.
</template>
</category>
.
.
.
<aiml>
see -- http://www.alicebot.org/aiml.html

Any suggestions are appreciated? Thanks