my %uid = ( 123 => 456, ... ); my %gid = ( 500 => 1024, ... ); open my $process_handle, "find $topdir -type f |"; while ( <$process_handle> ) { chop; # or chomp my($uid, $gid) = (stat)[4,5]; chown $uid{$uid}, $gid{$gid}, $_ if $uid{$uid} && $gid{$gid}; }