use strict;
my $str = '#images
https://www.google.com/search?q=finance&hl=en&tbm=isch&sxsrf=ALeKk03-wtxJ6IxBQ1QplyRfSUR5Zq6p5w:1588804525013&source=lnms&sa=X&ved=0ahUKEwjsstKKpqDpAhWIiqQKHeGbDWcQ_AUICygC&biw=2560&bih=1307&dpr=1
#books
https://www.google.com/search?q=finance&hl=en&sxsrf=ALeKk020ZKe6S8ZciwePz_FDqQNjlrIyMw:1588804501205&source=lnms&tbm=bks&sa=X&ved=2ahUKEwiuraX_paDpAhUHLBoKHbvWAKYQ_AUoAXoECBgQCQ&biw=2560&bih=1307
#all
https://www.google.com/search?q=finance&hl=en&sxsrf=ALeKk02-xP9nE6zHjjatj9fSG3th2_3zzw:1588804479887&source=lnms&sa=X&ved=0ahUKEwi0k5D1paDpAhWJ-qQKHW1XANcQ_AUIDSgA&biw=2560&bih=1307&dpr=1
#news
https://www.google.com/search?q=finance&source=lmns&tbm=nws&bih=1307&biw=2560&hl=en&ved=2ahUKEwi2jsnCpaDpAhWF44UKHcvnDusQ_AUoAXoECAEQAQ
https://www.google.com/
https://www.google.fr/
https://www.google.cm/
https://www.google.co.uk/
####Dont match following
#finance
https://www.google.com/search?hl=en&biw=2560&bih=1307&tbm=fin&sxsrf=ALeKk00e_wrvwwyEY7nhVKV8j5IvHPK8rQ%3A1588802138647&ei=WjKzXuX1JofVkwWv-p24Dg&q=finance&oq=finance&gs_l=finance-immersive.3...980.1734.0.1817.7.5.0.0.0.0.208.208.2-1.1.0....0...1.1.64.finance-immersive..6.1.208...81.0.T31TXEhQon8
#flights
https://www.google.com/flights?q=testt&bih=1307&biw=2560&hl=en&tbm=flm&sxsrf=ALeKk03tMI1tx59I3Jc-LJfPj3_gEihKyA:1588801776819&source=lnms&sa=X&ved=0ahUKEwiugJrsm6DpAhVNDOwKHRFgCLkQ_AUINSgD#flt=/m/04jpl..2020-05-22*./m/04jpl.2020-05-26;c:GBP;e:1;ls:1w;sd:0;t:h
#maps
https://www.google.com/maps?hl=en&biw=2560&bih=1307&sxsrf=ALeKk00e_wrvwwyEY7nhVKV8j5IvHPK8rQ:1588802138647&q=finance&um=1&ie=UTF-8&sa=X&ved=2ahUKEwiY2IGanaDpAhVFCewKHYSIDCwQ_AUoAHoECAEQCA
#shopping
https://www.google.com/search?q=testt&source=lmns&tbm=shop&bih=1307&biw=2560&hl=en&ved=2ahUKEwiShpzrm6DpAhUW_hoKHQ61AEcQ_AUoAnoECAEQAg
https://www.google.com/advanced_search?q=dictionary&rlz=1C1CHBF_enGB885GB885&sxsrf=ALeKk01ESVELxIjxyR_5vybRgq6D8oDKhg:1594571776832&hl=en';
my $regex = qr/^https?:\/\/www\.google((\..{1,3}){1,2})\/(search\?)?(?!flights|maps|advanced_search)(?!.*&tbm=(shop|fin)&).*/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