$m = ' more gib U berish"h" \n URL="http://[10.0.0.3]?id=80943lkjh875kjrvf09u548gfpi"\n gibber\n'; $u= qr/(?:.*(?=U)(?:URL="([^"]*)")?)*/s; #lookahead to 'U' if ($m =~ $u) { print "<$1>\n"; }else{ print "no match u\n";}