foreach ( @sorted ) { my $tar = Archive::Tar->new($_); ( my $dest = "./EXTRACTED/$_" ) =~ s/\.t(?:ar(?:.gz|gz)//; mkdir $dest unless ( -d $dest ); chdir $dest or die "mkdir/chdir failed on $dest: $!"; $tar->extract(); # no params: extract full content to cwd chdir "../.."; # return to original cwd } #### for my $file ( $tar->get_files ) { my $dataref = $file->get_content_by_ref; # open a suitable output file and print $$dataref to it. # You can use $file->name to see the tarred path and # make subdirs as you see fit. }