in reply to Splitting the record using the delimiter

Instead of splitting away what you don't want, consider matching what you want to keep:

my @code = ($id =~ /([^|\\]+|\\[|\\])/g);

Also see Text::CSV_XS.