use warnings; use strict; use Data::Dump 'pp'; use Text::ParseWords 'shellwords'; use Getopt::Std 'getopts'; my $stdin = q{ -a "hello world" -b "some \"text\"" -c 'abc def' }; my %opts; { # for local; avoid messing with global @ARGV local @ARGV = shellwords($stdin); pp \@ARGV; getopts('a:b:c', \%opts) or die "bad options"; pp \%opts, \@ARGV; } __END__ ["-a", "hello world", "-b", "some \"text\"", "-c", "abc def"] ( { a => "hello world", b => "some \"text\"", c => 1 }, ["abc def"], )