my @tests = ( '', qw( 2|3||||| 2 2| 2|3 2|3| | |2 |2| |2|3 |2|3| )); for my $string (@tests) { # Splits on '|' and preserves empty fields... my @fields = $string =~ m/((?:^|(?<=\|))[^|]*)/g; printf "%-10s :", "'$string'"; print "($_)" for @fields; print "\n"; } __END__ '' :() '2|3|||||' :(2)(3)()()()()() '2' :(2) '2|' :(2)() '2|3' :(2)(3) '2|3|' :(2)(3)() '|' :()() '|2' :()(2) '|2|' :()(2)() '|2|3' :()(2)(3) '|2|3|' :()(2)(3)() #### my @fields = split /\|/, $string.'|x'; pop @fields;