use strict;
my $str = ' <ProjectReference Include="..\\..\\Project1\\Project1\\Project1.csproj">
<Project>{714c6b26-c609-40a4-80a9-421bd842562d}</Project>
<Name>Project1</Name>
</ProjectReference>
<ItemGroup>
<ProjectReference Include="..\\..\\Project2\\Project2.csproj">
<Project>{6c2a7631-8b47-4ae9-a68f-f728666105b9}</Project>
<Name>Project2</Name>
</ProjectReference>
<ProjectReference Include="..\\..\\Project3\\Project3\\Project3.csproj">
<Project>{39860208-8146-429f-a1d1-5f8ed2fd7f5f}</Project>
<Name>Project3</Name>
</ProjectReference>
<ProjectReference Include="..\\..\\Project4\\Project4.csproj">
<Project>{58144d60-19d9-4d11-8ae6-088e03ccf874}</Project>
<Name>Project4</Name>
</ProjectReference>
<ProjectReference Include="..\\..\\Project5\\Project5.csproj">
<Project>{33baa509-ad24-4a72-a2fc-8f297e75e90d}</Project>
<Name>Project5</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="\'$(VisualStudioVersion)\' == \'\'">10.0</VisualStudioVersion>
<VSToolsPath Condition="\'$(VSToolsPath)\' == \'\'">$(MSBuildExtensionsPath32)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>';
my $regex = qr@(<ProjectReference.*?Project2[\s\S]*?</ProjectReference>)@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