Now do it when you don't know what the text is up front and the text varies from line to line.
With this version you might as well just have used a print statement containing the litteral output. I'm sure in OP's real problem the text is not as shown. A better sample may have comprised words like "foo bar baz" and been much shorter, but there were enough lines there that you should probably have been able to read between them. :).
DWIM is Perl's answer to Gödel