in reply to How to extract the filenames in an array

Welcome to PerlMonks!

Let's say we have the path: /login/user/temp/file.txt

Imagine splitting the path names into 5 containers. This is how we would do it:
#!/usr/bin/perl -l use warnings; use strict; use File::Spec::Functions qw(splitdir); my $path = '/login/user/temp/file.txt'; my @names = splitdir $path; print $names[0]; # prints: "" print $names[1]; # prints: "login" print $names[2]; # prints: "user" print $names[3]; # prints: "temp" print $names[4]; # prints: "file.txt"

The first array element is an empty string because nothing comes before the first directory separator of $path.