#!/usr/bin/env perl use strict; use warnings; my $filename = '/home/someuser/foo.zip'; my $read = `unzip -l $filename`; # Read in the output of the unzip -l command. chomp(my @contents = split /\n/, $read); # Note: # $contents[0] contains the archive name. # $contents[1] contains the header. # $contents[2] contains a header delimiter ------. # $contents[3] contains the first file listing. # ..... # $contents[-3] contains last file listing. # $contents[-2] contains a footer delimiter ------. # $contents[-1] contains a summary. my $pos = index $contents[1], 'Name'; # Find the 'Name' field. The start of that field is # the position in subsequent lines where filenames # begin. my $n = 1; # Keep track of row number, just because. foreach my $item (@contents[3 .. $#contents - 2]) { # Start with the first file entry, and end with the last file entry. my $filename = substr($item, $pos); # Use our index position to look for a substring starting where # the Name field began. print $n++, ": $filename\n"; # Print out output. }