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