use strict; use warnings; use Data::Dumper; use Text::ParseWords; my $str = 'command1 command2 command3 "command4 --some-arg arg --some-other-arg 2" command5'; my @words = shellwords($str); print Dumper(\@words);