in reply to split problem when emptiness is a valid element

Use the limit argument on split. Specify a negative number to keep all empty records.
use Data::Dumper; my @array = split /\|/, 'A|B||', -1; print Dumper(\@array);
gives
$VAR1 = [ 'A', 'B', '', '' ];
from the docs for split:
split /PATTERN/,EXPR,LIMIT

...

If LIMIT is specified and positive, it represents the maximum number of fields the EXPR will be split into, though the actual number of fields returned depends on the number of times PATTERN matches within EXPR. If LIMIT is unspecified or zero, trailing null fields are stripped (which potential users of pop would do well to remember). If LIMIT is negative, it is treated as if an arbitrarily large LIMIT had been specified.