use strict; use warnings; my @path= split /\//,'/abc/def/ghi/jkl'; my $currentpath= undef; while ($#path) { $currentpath= join '/',@path # your setfacl here last if -r $currentpath; $currentpath= undef; pop @path; } die "Couldn't setfacl" unless $currentpath;