/[^\\]\\((\\)+\1)*$/ #### #!/usr/bin/perl -w use strict; my @split; my $var; # the original string that I want to split my $tosplit = q(a=1&b=2\&3&c=4\\\\\&d=5); # print out the string to confirm how many backslashes have been left # by the quote statement print $tosplit . "\n\n"; # Split the string on the ampersand my @temp = split /&/, $tosplit; # I thought this should have joined any two strings that were # previously separated by an odd number of backslashes at the # end of a string. while ($_ = shift @temp) { $_ .= ("&" . shift @temp) and redo if /[^\\]\\((\\)+\1)*$/; push @split, $_; }; foreach $var (@split) {print "$var" . "\n"};