in reply to splitting on multiple delimiters
use strict; use warnings; my $str = 'command1 command2 command3 "command4 --some-arg arg --some- +other-arg 2" command5'; for (split m{(\s+|"[^"]*")}, $str) { print $_, $/; }
That works, but produces a few strings that only contain whitespaces - you can filter them in a separate pass, for example with grep.
The other solution is match your desired output, not the delimiter.
Update: version with filtering:
use strict; use warnings; my $str = 'command1 command2 command3 "command4 --some-arg arg --some- +other-arg 2" command5'; for (split m{(\s+|"[^"]*")}, $str) { next if m/^\s/; next unless length $_; print "<$_>\n"; }
|
|---|