in reply to While loop printing only one fasta header file

The first header in $line reads through the whole file and then for the second and subsequent headers the filehandle FH will return eof.   You need to either open $fn inside the foreach loop or use seek to return the filehandle to the beginning of the file inside the foreach loop.