I read your question a little differently, so maybe this is what you are thinking: You read in the whole file with something like @array=<FILE>; but any blank lines at the end of the file gave you empty array elements. Removing the trailing newline from the elements still leaves you with empty elements. Clean this up with: pop @array while (@array && $array[-1] eq '');