sub MySplit2 { # args being like split but with the third INSTEAD a # preservation delimiter -- the OP requirement seems # to suggest that should be -1 for split anyway my $pat = shift; my $str = ( shift () || $_ ); my $pat2 = shift; # a preservation delimiter # i.e. not splits usual arg3 my @return = (); my $inquotes = 0; for my $qs ( defined ( $pat2 ) ? ( split( /$pat2/, $str, -1 ) ) : ( $str ) ) { push @return, $inquotes ? $qs : split( /$pat/, $qs, -1 ); $inquotes = !$inquotes; } return @return; }