use strict;
my $str = 'NAME="loop0" FSTYPE="LVM2_member" MOUNTPOINT="" SIZE="20971520000" TYPE="loop"
NAME="sda" FSTYPE="" MOUNTPOINT="" SIZE="171798691840" TYPE="disk"
NAME="sda1" FSTYPE="ext4" MOUNTPOINT="/boot" SIZE="1073741824" TYPE="part"
NAME="sda2" FSTYPE="LVM2_member" MOUNTPOINT="" SIZE="170723901440" TYPE="part"
NAME="sdb" FSTYPE="" MOUNTPOINT="" SIZE="32212254720" TYPE="disk"
NAME="sdb1" FSTYPE="LVM2_member" MOUNTPOINT="" SIZE="32211206144" TYPE="part"
NAME="sdc" FSTYPE="" MOUNTPOINT="" SIZE="53687091200" TYPE="disk"
NAME="sdc1" FSTYPE="LVM2_member" MOUNTPOINT="" SIZE="53686042624" TYPE="part"
NAME="sr0" FSTYPE="" MOUNTPOINT="" SIZE="1073741312" TYPE="rom"
NAME="cl_ctos8auto-root" FSTYPE="xfs" MOUNTPOINT="/" SIZE="106300440576" TYPE="lvm"
NAME="cl_ctos8auto-root" FSTYPE="xfs" MOUNTPOINT="/" SIZE="106300440576" TYPE="lvm"
NAME="cl_ctos8auto-swap" FSTYPE="swap" MOUNTPOINT="[SWAP]" SIZE="8497659904" TYPE="lvm"
NAME="cl_ctos8auto-home" FSTYPE="xfs" MOUNTPOINT="/home" SIZE="108536004608" TYPE="lvm"
NAME="cl_ctos8auto-var_log" FSTYPE="ext4" MOUNTPOINT="/opt/imsdb/chroot-sybase/var/log" SIZE="32208060416" TYPE="lvm"
NAME="b38ad718--fc07--11ea--9894--0050569ae644-fea1a18c--fc07--11ea--9894--0050569ae644" FSTYPE="ext4" MOUNTPOINT="/opt/intelerad/atlas/1/storage/b30f29df-8fc2-4db5-8c17-4275cdae6b3f" SIZE="20967325696" TYPE="lvm"';
my $regex = qr`(?m)^NAME="(?P<name>(?P<disk>[a-z]+)(?P<partition>\d*))"\sFSTYPE="(?P<fstype>\w*)"\sMOUNTPOINT="(?P<mountpoint>[\w\[\]/]*)"\sSIZE="(?P<size>\d*)"\sTYPE="(?P<type>\w+)"$`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