my $ff_exe = q{C:\\Program Files\\Mozilla Firefox\\firefox.exe}; my @cmd = ($ff_exe, '--version'); my $shell_command = join " ", # separate by spaces map { /\s/ ? qq{"$_"} : $_ } # enclose in double quotes if needed @cmd; print $shell_command;