my $fieldcount = $string =~ tr/|/|/ + 1; my @fields = split(/\|/, $string, $fieldcount);