use strict;
my $str = 'folder.jpg
metadata
Stargate SG-1 S01E01-E02 Children of the Gods.mkv
Stargate SG-1 S01E03 The Enemy Within.mkv
Stargate SG-1 S01E04 Emancipation.mkv
Stargate SG-1 S01E05 The Broca Divide.mkv
Stargate SG-1 S01E06 The First Commandment.mkv
Stargate SG-1 S01E07 Cold Lazarus.mkv
Stargate SG-1 S01E08 The Nox.mkv
Stargate SG-1 S01E09 Brief Candle.mkv
Stargate SG-1 S01E10 Thor\'s Hammer.mkv
Stargate SG-1 S01E11 The Torment of Tantalus.mkv
Stargate SG-1 S01E12 Bloodlines.mkv
Stargate SG-1 S01E13 Fire and Water.mkv
Stargate SG-1 S01E14 Hathor.mkv
Stargate SG-1 S01E15 Singularity.mkv
Stargate SG-1 S01E16 Cor-Ai.mkv
Stargate SG-1 S01E17 Enigma.mkv
Stargate SG-1 S01E18 Solitudes.mkv
Stargate SG-1 S01E19 Tin Man.mkv
Stargate SG-1 S01E20 There But For the Grace of God.mkv
Stargate SG-1 S01E21 Politics (1).mkv
Stargate SG-1 S01E22 Within the Serpent\'s Grasp (2).mkv
';
my $regex = qr//*.mkv/p;
if ( $str =~ /$regex/ ) {
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