Depending on the complexity of your situation, tools like
Parse::RecDescent can also be useful. This is a very efficient, industrial-strength
parser which allows you to define the structure of your input using a
grammar. You might not need it here, but, "when you do need it, you will know."