All the previous responses do work, they just only work on the last two lines of the file. I was wondering if there was a simple Perl-related explanation for it.
I'm sorry if I'm posting too much, I don't mean to be annoying. I debated long and hard over whether to post again, and finally decided to because otherwise I'd just sit around worrying about it.