>perl -wMstrict -le "my $rx = qr{ \A (?! (?i) .* \bfirst\b ) This .* \. \z }xms; print '----- output -----'; for my $str (@ARGV) { print $str, $str =~ $rx ? ' M' : ' No M', 'atch'; } " "This is first sentence." "This is second sentence." "This is the First Lady." "This is the firstborn." ----- output ----- This is first sentence. No Match This is second sentence. Match This is the First Lady. No Match This is the firstborn. Match