use strict; while (<>) { /\bit (.*)[.?!]$/i and print $1,$/; }