in reply to Outputting contents of ls -lt

Put the return value from ls into a variable, and filter the file names for the extensions you want to allow. It's better to do it this way than filtering through ls, imho.

EDIT: Here's some code:

#!/usr/local/bin/perl use strict; use warnings; my $base = '/u/web/user/'; my @allow = qw/log txt sql err par csv/; my $e; print "Content-type: text/plain\n\n"; for (split /\n/, `ls -lt $base`) { for $e (@allow) { if (m/\.$e$/) { print "$_\n"; last; } } }
The advantage of doing it this way is that your code is easy to modify to work with rejected lines, should you decide you want to in the future.