perl -nlwe 'print $1 if /\bit\b(.*[.?,])$/' text-file #### perl -nlwe '/[.?,]$/ && /\bit\b/ && print $'"'" text-file