use strict; use warnings; my $start_date = $ARGV[0] || 'bogus'; die "bad argument" unless $start_date =~ /\d{8}/; my $archive_dir = '/dir/archive/'; my @files = qx('ls' $archive_dir); chomp @files; @files = sort {$b <=> $a} grep /^20\d{6}$/, @files; for my $file( @files ){ last if $file < $start_date; my $fullpath = $archive_dir . $file; print "$fullpath\n"; # for testing # Issue shell cmds here, e.g. # qx( 'cp' $fullpath $fullpath'.bkup'); # to back up files before proceeding. } #### my $start_date = $ARGV[0] || 'bogus'; die "bad argument" unless $start_date =~ /\d{8}/; my $end_date = $ARGV[1] || 'bogus'; die "bad argument" unless $end_date =~ /\d{8}/; ... #### next if $file > $end_date; last if $file < $start_date; ...