Your statement of the problem is incomplete, as mentioned already by
GotToBTru: we don't know how to figure out that you need to go to the next row. You mention new line in the pseudo-code, but there is no new line in your data sample (or perhaps you should read
Markup in the Monastery, data samples examples should have the same tags as code).
Having said that, any good introduction to or tutorial for Perl should tell you how to split a space-separated line into an array. I hope this clue helps you for the start.