use strict;
my $str = 'https://www.facebook.com/hung.le054
https://www.facebook.com/groups/j2team.community/?ref=nf_target&fref=nf&__xts__%5B0%5D=68.ARCufAkDYLfgBw09Ctl9HKUd8wMYIaATKYHE-9guWWpCGu86iH8k0p4Qx8BxlXEEJMW8shzzodIckx0qvnBg94kwMe3uOIPnjE9s6neoXwFX8kBJsWBpF-Ej8oXpGdiIu6sf9cg9tyeq&__tn__=C-R
https://www.facebook.com/NoExit.GoEXID/?hc_ref=ARQCFBLI4l-ciKCPEGazrn4_8WTxAulTr9a7XgMTgi_OKA_Iad1-hMzdD2z0snaq3BE&fref=nf&__xts__%5B0%5D=68.ARAUlT1DqV2wkn3VWI7belmtRn5k9XXk05WUw1Gl88lm2CDjGSmYX0zI_p8A19EG2w6iWF3t0gZN-GurkpGl05KGdS5Xv8lC__sOmlxD8Jz5CrhOjbz1ThvYtiZA3yzk4P66-V5BjDty&__tn__=kCH-R
https://www.facebook.com/profile.php?id=100010004806283&fref=pb&hc_location=friends_tab';
my $regex = qr/(?<=profile\.php\?id\=)(?<id>[0-9]+)|(?:(?<=\.com)|(?<=\.me)|(?<=\.co)|(?<=\.us))(?:(?:\/groups\/|\/)(?!profile\.php)(?<username>[\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