If your objective is to create a new tar file containing a subset of files drawn from an old tar file, (e.g. just the files whose names end in ".gz"), check the man page for your tar utility (use the shell command "man tar" if your on a unix box, or maybe "info tar" on a cygwin setup). You might be able to just do a command line like this (no need for a perl script):
tar cf new.tar --include='*.gz' @old.tar
(That's doable with the current freebsd version of tar, which derives from GNU tar, so the latter probably supports the same sort of usage.)