in reply to Wierd error message

Perhaps adding next if not defined $_[0]; as the first line of the while loop body? It's hard to tell if there's a better approach or not without more complete (working?) example.