A more idiomatic way to remove newlines is
@molecules = grep { $_ ne "\n" } @molecules; [download]
In reply to Re: Deleting specific array elements by moritz in thread Deleting specific array elements by joec_