$m = ' more gibberish"h" \n URL="http://[10.0.0.3]?id=80943lkjh875kjrvf09u548gfpi"\n gibber\n'; $u= qr/(:?URL="([^"]*)")?/is; # optional clause (:?xxx)? if ($m =~ $u) { print "<$1><$2>\n"; }else{ print "no match u\n";} #### [tmp]> perl testResp2.pl <><> [tmp]> #### $u= qr/.*(?=U)(?:URL="([^"]*)")?/s # moves to just before 'U' #### $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";} #### $p= qr/RESPONSE\sid="([^"]+?)" .* #random XML disposition="([^"]+?)" .* #random XML (?:.*(?=U)(?:URL="([^"]+?)")?)* /sx;