The reason your regex
name_of_file\(\d{6}).A\d{3}
# ^^--- escaped parenthesis
Does not work is because it expects a literal parenthesis ( in your string. Since there are none, this will never match.
This regex
name_of_file(\d{6}).A\d{3}
Will not match, since you have it "anchored" between name_of_file and .A, with no allowance for characters in between.
The simplest fix to allow extra filler numbers is to simply add \d* before your capture area. You should also escape . since it is a regex meta character that means "match any character except newline".
name_of_file\d*(\d{6})\.A\d{3}
This will now allow the regex to match more loosely with strings such as
name_of_file0000000546210618.A001.6476871457
# ^^^^^^^^^^---- unneeded numbers
Similarly, you could just remove the anchor before the numbers
(\d{6})\.A\d{3}
It is strange to me to have the string name_of_file in a regex. If it is a placeholder for an actual file name, it would mean that you hard code a file name in your regex, meaning it will only match that exact filename, and nothing else. Usually, you want regexes to match a number of different type of strings. I would expect a regex to match different file names to look something like:
[\pL_]+\d*(\d{6})\.A\d{3}
#^^^^^^-- matching letters and underscore
It seems like what you need to capture, however, is not the number, like your regex shows, but the filename also, in a string like this: name_of_file210618.A001. In that case, you would need to perform some more operations. It might be possible to execute with a substitution to remove unwanted characters, but it is much simpler to just use a regex and concatenation, like this
use strict;
use warnings;
use Data::Dumper;
while (<DATA>) {
my ($name, $num) = /([\pL_]+)\d*(\d{6}.A\d{3})/;
my $str = join '', $name, $num;
print Dumper $str;
}
__DATA__
name_of_file210618.A001.6476871457
name_of_file0000000546210618.A001.6476871457
foo_of_bar210618.A001.6476871457
This will print
$VAR1 = 'name_of_file210618.A001';
$VAR1 = 'name_of_file210618.A001';
$VAR1 = 'foo_of_bar210618.A001';