#!/usr/bin/perl # Note: file must be in same directory, or else # must specify an absolute path opendir(CDIR, "."); # . gives current directory # get only filenames ending in .txt; escape the . character @filenames = grep( /\.txt/, readdir(CDIR)); @filenames = sort(@filenames); # sort them! closedir(CDIR); foreach $filename(@filenames) { print "$filename\n"; }