in reply to basic question on split

You'll need to replace length(@rest) with scalar(@rest); length is for strings only, not arrays.