use strict;
my $str = 'facebook
face book
faceBook
Facebook
FaceBook.com
https://facebook.com/99402349034
facebook.com
facebook.com/
face
book
facebook.com
face-book.com
394023894230984
https://facebook.com/zuck
https://www.facebook.com/profile.php?id=100001533612613
https://m.facebook.com/ChrisHughes
facebook.com/id=xkdjfksjdflkdjfk
https://www.facebook.com/profile.php?100001533612613
https://www.facebook.com/profile.php?id=1d00001533612613
https://www.facebook.com/akld20322k332
https://www.facebook.com/profile.php?id=100001533612613
';
my $regex = qr/(?i)((face*book|(\bface.*book|face.*book.com\b/)).+\d)|(face.*book)|(\bface.*book|face.*book.com\b/.*id\S+\d)|(face.*book.com\b/.*id.\d+.*)/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