in reply to Closing program when end of files is reached

Change:
while (<FHIN>) { $line=$_;
to this:
while (<FHIN>) { $line=$_; next if $line =~ s/^\s*$/;
This will cause the while loop to skip to the next iteration for lines which are blank or only contain whilespace. In your case it's only the last line, but you can never trust user supplied data :)

/\/\averick