#!/usr/bin/perl -w use File::Glob qw(bsd_glob); my $source_dir = "/home/haim/tmp/lists"; sub init_source_list { chdir $source_dir or die "Cannot change dir to $source_dir! ($!)"; while (defined($sourcefile = bsd_glob("*"))) { # for every file in this # directory if (-d $sourcefile) { # if the file is actually a directory... while (defined($ver = bsd_glob("$sourcefile/*"))) { #$ver =~ s/.*\///; #remove everything before the "/". $apps{$sourcefile}{$ver} = undef; # add an empty key to # %apps{$sourcefile} } } else { $apps{$sourcefile} = undef; # add an empty key in the hash # %apps } } } &init_source_list; foreach $key (keys %apps) { if (keys %{ $apps{$key} }) { foreach $vkey (keys %{ $apps{$key} }) { print "$source_dir/$key/$vkey\n"; } } else { print "$source_dir/$key\n"; } }