How does a fasta header in your input file look like? I tried to reproduce the behavior you are alluding to by using your code and a couple of fasta sequences, but your code seems to be working just fine.
A side notice on your first code
(open FILE, "mRNA.fa" or die $!;). That open statement lacks telling it what mode you want to open mRNA.fa into. It is a good practice to decide if you want to open your file for input, output or appending. The second open statement from the newer code is a better way of opening a file since you have instructed open on the type of mode you want to open your file in.