use IO::Compress::Gzip qw(gzip $GzipError) # other code... IO::Compress::Gzip::gzip(\$content, \$newContent) or die "gzip failed: $GzipError\n"