#! /usr/local/bin/perl use strict; use warnings; use File::Basename 'dirname'; my $path = shift || '/usr/local/bin/perl'; my @ancestor; while (1) { $path = dirname($path); last if $path eq '/'; push @ancestor, "$path/"; } print "$_\n" for reverse @ancestor;