in reply to Surprised by split

You are getting stuffed up by the quoting here. You should bear in mind in the first instance that the first argument to split is a regular expression, and it is often prefered use the // rather than quotes. In your first attempt you are asking to split on anything or anything ('|' being the regex alternation character), in your second you are basically getting the same thing because the '\' is being eaten in the double quoted context (i.e. escaping the '|') and the third is correct because you are now escaping the '\' so you get a literal '\|'. You probably want to either use single quotes or the // for clarity.

use warnings; use strict; + my $str = "lhs|rhs"; + print "\n" . join " ", split '\|', $str; print "\n" . join " ", split /\|/, $str;

/J\