in reply to splitting on multiple delimiters

This solution does the split on whitespace passed into a map which maintains a state engine, agregating the commands and arguments and passing an undef onwards if within quotes; a grep is then used to get rid of the undefs. It is a little like punch_card_don's solution in concept. It will not cope with escaped double quotes as it stands.

#!/usr/bin/perl -l # use strict; use warnings; my $string = q{command1 command2 command3 "command4 --some-arg arg --some-other- +arg 2" command5}; my $inQuotes = 0; my $agregator = q{}; my @cmds = grep { defined } map { if ( $inQuotes ) { if ( m{"$} ) { s{"}{}; $agregator .= qq{ $_}; $inQuotes = 0; $agregator; } else { $agregator .= qq{ $_}; undef; } } elsif ( m{^"} ) { s{"}{}; $inQuotes = 1; $agregator = $_; undef; } else { $_; } } split m{\s+}, $string; print for @cmds;

The output.

command1 command2 command3 command4 --some-arg arg --some-other-arg 2 command5

I hope this is of interest.

Cheers,

JohnGG