use strict;
my $str = 'Patate_17890505_TitreEnCamelCase.ext
EPFL_AlgebreLineaire
TaxonomieProprietesFonctionsComplexes.v0.ipe.20210302_005606.pdf
1_
12_
_1
_12
12345678_
_123456
12345678_12345
1234567_123456
1234567_12345
123456_12345
12345678_1234567
123456789_123456
123456789_1234567
_patate__truc__
___
foo_12345678
foo_12345678_123456_bar
12345678_123456
foo12345678_123456bar';
my $regex = qr/(?<!(?<!\d)\d{8})_(?!\d{6}(?!\d))/mp;
my $subst = '.';
my $result = $str =~ s/$regex/$subst/rg;
print "The result of the substitution is' $result\n";
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html