use File::Basename; opendir(DIR, "/template/dir") or die "can't open dir: $!"; # I'm guessing at the template extension if there is one @templates = grep { /\.tmpl$/ } readdir DIR; closedir DIR; my %printers; for my $file (@templates) { open (FH, $file) or die "Error opening $file: $!"; my $name; while () { chomp; my ($tmp_name, $value) = split /\s*:\s*/; $name = $tmp_name if $tmp_name; $value =~ s/,$//; $printers{basename($file)}{$name}{$value} = undef; } close FH; } # Now %printers contains all valid printer attributes # and their values