# Build encryption command my $gpg_command = "gpg --trust-model always -er 12345678 my_file.txt"; # Execute command and capture STDOUT. my $gpg_results = `$gpg_command`; print defined($gpg_results) ? $gpg_results : "Command failed\n"; # Save captured STDOUT to a file. open( my $out, ">", "encrypted.pgp" ) or die "Could not open file for encrypted data - $!";