chdir ($folder); while ($file = <*>){ my ($ext) = $file =~ /(\.[^.]+)$/; #Check file extension if (($ext =~ m/00./) and ($ext ne ".001")){ next; } elsif ($ext eq ".001") { # first file is required my $filenameroot = $file; $filenameroot =~ s/(.+)\.[^.]+$/$1/; # File name root my @list = glob("$folder$filenameroot*"); print "Last element : $list[(scalar @list-1)]\n"; # Last file of the series } }