#!/usr/bin/perl use Capture::Tiny qw/ capture /; use String::ShellQuote; my ($stdout,$stderr,$exit) = capture { my $command = " curl -s --user \'api:key*****\'"; $command .= " https://api.****/**/*****/messages"; $command .= " -F from='*****'"; $command .= " -F to=\'Name <$to_id>\'"; $command .= " -F subject=\'$subject\'"; $command .= " -F text=\'$message\'"; my $message = " -F text=\'test a new line\'"; @args = ($message); #this works system $command ; #this doesnt. result is -1 system $command @args; #this doesnt either. result is -1 system $command shell_quote @args }; print $stdout,$stderr,$exit;