my $dir = shift || '.'; opendir DIR, $dir or die "Can't open directory $dir: $!\n"; while (defined (my $file = readdir DIR) ) { next if $file !~ /^\w{10,}\d{4,}\.\d{1,}/; print "Found a file: $file\n"; print "are you sure that you want to delete $file 'Y/y(es)' "; chomp( my $answer= ); do { unlink "$dir/$file" or die "Can't delete $file: $!\n" } if $answer =~ m%^Y(es)?$%i; }