#!/usr/bin/perl -w use strict; my @strings = ( 'HITMUST MATCH 2', 'HIT- 2' ); foreach my $string (@strings) { "" =~ /()/; # set $1 to false $string =~ / ( # the whole match should be catches as $1 HIT # start at the first found "HIT" (?= # begin of positive Lookahead [^<]*? # zero or more characters other than "<" (?! # start a negative Lookahead ]*?> # an opening a tag is forbidden ) .*?<\/a> # any characters until the closing a tag ) # end of positive Lookahead .*? # catch all chars after HIT, <\/a> # non-greedy until the first closing a tag ) /x; print "\nstring:\t$string\n"; if ($1) { print "match:\t$1\n" } else { print "NO match!\n" } }