my $str = "/One/Two/Three"; my @paths = ($str); push @paths, $str while($str =~ s{^(/.+)/[^/]*$}{$1}); print "$_\n" for @paths; #### /One/Two/Three /One/Two /One