use IO::Compress::Gzip qw(gzip $GzipError) # other code... IO::Compress::Gzip::gzip(\$content, \$newContent) or die "gzip failed: $GzipError\n" #### my @transferFileContents = ; foreach(@transferFileContents) { $content .= $_; } #### $content = do { local $/; my $rv = ; $rv }; #### $content = do { # minimize scope local $/; # make input separator undef 'till the end of this scope my $rv = ; # get all contents $rv # return it };