opendir my $DH, '.' or die "Cannot open the current directory: $!"; while ( my $file = readdir $DH ) { next if '.txt' ne substr $file, -4;