in reply to Sub only grabbing first line from STDIN

All the problems noted so far would have been pointed out to you by Perl itself if you had use warnings (or -w if your Perl is older). You could also add some indentation in your loop to show the flow better, and some error checking (e.g. die if your open fails) would help you out too. For instance, if you use warnings you should get a message about printing to a closed filehandle, and also probably a message about $text not being numeric as an array index, which would point out the error that boo_radley noted above. You will also find that use strict helps immeasurably in making you think about your use of variables.

--
I'd like to be able to assign to an luser