in reply to Deleting specific array elements

If $mol eq "\n" then scalar($mol) is still \n, and not a number. But splice expects a number as second (and third) argument.

A more idiomatic way to remove newlines is

@molecules = grep { $_ ne "\n" } @molecules;