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 )= $string =~ /.*($PATTERN)/sg; print $last, $/; $last= ( $string =~ /($PATTERN)/g )[-1]; print $last, $/; __END__ prints: JKL JKL never: HI JKL