my $string= " AB CDE FG HI JKL "; my $PATTERN= qr/(?! F)(?: \w+){1,3} /; # (match space-separated words where the first doesn't start with "F") my $last; my $end= -1; while( $string =~ /(?=($PATTERN))/g ) { my $stop= $+[-1]; if( $end < $stop ) { $last= $1; $end= $stop; } } print $last, $/; __END__ prints " HI JKL " !