To compress a file in Perl, it’s better to use the gzip method. For that we can use the module use IO::Compress::Gzip qw(gzip $GzipError) ;.
Eg:-
use IO::Compress::Gzip qw(gzip $GzipError) ;
my $input="new.pdf";
my $output="new1.pdf.gz";
gzip $input => $output or die "gzip failed: $GzipError\n";