#!/usr/bin/perl use strict; use warnings; my %dir_chmod = (x => 0777, z => 644); my %file_chmod = (x => 644, y => 666, z => 644); mychmod('dir',%dir_chmod); mychmod('file',%file_chmod); sub mychmod{ my ($type,%hash) = @_; for my $dir(keys %hash){ opendir DIR, $dir or die $!; my @entries = map{$dir . '/' . $_} grep{!/^\.\.?$/ and ($type eq 'file' ? -f $_ : -d $_)}readdir DIR; closedir DIR; chmod $hash{$dir},@entries; } }