$ tar txf syssrc.tgz > /tmp/file #### #!/usr/bin/perl use strict; use warnings; use Readonly; Readonly my $filename => '/tmp/contents'; my $args = 'tf'; eval { die 'incorrect #command-line arguments' unless @ARGV == 1; # add switches based on filetype if ($ARGV[0] =~ /tgz$/) { $args .= 'z'; } # dump tar contents to file if (system('tar', $args, $ARGV[0]) != 0) { if ($? == -1) { die "failed to execute '$!'"; } elsif ($? & 127) { die sprintf 'child process died with signal %d %s', ($? & 127), (($? & 128) ? 'with coredump' : ''); } else { printf "child process exit value:\t%d\n", ($? >> 8); } } }; if ($@) { $@ =~ s/at $0 line \d+\.$//; print "syntax:\t$0 \n"; print "error:\t$@\n"; } ..but if I change the system() call to: if (system('tar', $args, $ARGV[0], '>', $filename) != 0) { #### tar: WARNING! These patterns were not matched: > /tmp/contents child process exit value: 1