<?xml version="1.0" encoding="windows-1252"?>
<node id="1002272" title="Re: Trouble splitting pipe delimited" created="2012-11-04 23:40:24" updated="2012-11-04 23:40:24">
<type id="11">
note</type>
<author id="421114">
Tanktalus</author>
<data>
<field name="doctext">
&lt;p&gt;I'll second the anonymous monk's suggestion to use Text::CSV (or, better, Text::CSV_XS):
&lt;c&gt;use Text::CSV_XS;
use feature 'say';
use warnings;

my @tests = (
             [q[1|str|foo\\|bar|goo|2323] =&gt; [qw(1 str foo|bar goo 2323)]],
             [q[foo\\\\|bar] =&gt; [qw(foo\\ bar)]],
            );

for my $t (@tests)
{
    my $s = $t-&gt;[0];
    my @e = @{$t-&gt;[1]};

    my $csv = Text::CSV_XS-&gt;new(
                                {
                                    sep_char =&gt; '|',
                                    escape_char =&gt; '\\',
                                }
                               ) or die "" . Text::CSV_XS-&gt;error_diag();
    $csv-&gt;parse($s);
    my @o = $csv-&gt;fields();

    say "$s\n  @e\n  @o\n";
}
&lt;/c&gt;
The regex/split suggestions fail to take into consideration a doubled escape prior to a delimiter (see the second test).  For your example, that may be fine, but your example is so obviously contrived that it can't be taken definitively.&lt;/p&gt;
&lt;p&gt;Output:
&lt;c&gt;$ perl5.16.2 x.pl
1|str|foo\|bar|goo|2323
  1 str foo|bar goo 2323
  1 str foo|bar goo 2323

foo\\|bar
  foo\ bar
  foo\ bar
&lt;/c&gt;
Hope that helps.&lt;/p&gt;</field>
<field name="root_node">
1002256</field>
<field name="parent_node">
1002256</field>
</data>
</node>
