#!/usr/bin/perl use IO::Compress::Gzip qw(gzip $GzipError); use Getopt::Long; #usage: $0 --gzip my $useGZ; my $options = &Getopt::Long::GetOptions( 'gzip|z' => \$useGZ ); my $OUT_FHs; my $out_file = "test.txt"; if($useGZ) { $OUT_FHs = new IO::Compress::Gzip ("$out_file.gz") or die $GzipError; } else { open $OUT_FHs, '>', $out_file or die "Can't open $out_file for writing; $!\n"; } print $OUT_FHs "printing to test file\n"; close($OUT_FHs); exit;