#!/usr/local/bin/perl -w use strict; opendir( DIR, './' ); my @files = readdir( DIR ); closedir( DIR ); my $i = scalar @files; foreach my $file ( @files ) { $i--; # do something with the items in list if ( $i == 0 ) { # do something special with last one. } }