use strict;
my $str = 'cid:d09004b7478a4f338bf647519edf71a3/tag:1595602064/aid:095438ff38da41e4444059fdbd9af9fd/pid:64756d6d792c484f555345424152415448454f4e2c31302e3136302e332e3232342c323032302d30372d32375432325f35385f31315a2e786d6ce3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855/mod_dirlist-part-000001.json.gz';
my $regex = qr`.*mod_(\S+?)(-part-\d+)?\.(csv|json)`mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
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