use strict; use warnings; my $file = 'test.txt'; my $recipient = 'joe@example.com'; my ($armor) = (0); # 1 to generate ascii, 0 to work with binary system('gpg', $armor ? qw(--armor) : (), '--recipient' => $recipient, '--encrypt' => $file) and die "Exit code: $?"; system('gpg', '--output' => "${file}_decrypted", '--decrypt' => $file . ($armor ? ".asc" : ".gpg")) and die "Exit code: $?"; system('gpg', $armor ? qw(--armor) : (), "--output" => "${file}.sig", '--detach-sign' => $file) and die "Exit code: $?";