in reply to problem in splitting on special character

Your second split is attempting to use ~ as the match character, not |. Did you intend to use $sep? Actually, even that won't do what you want because you need to quote | (it is a regex meta character). Something like:

@arr = split /\Q$sep\E/, $var;

DWIM is Perl's answer to Gödel