use strict; while (<>) { /\bit (.*)[.?!]$/i and print $1,$/; } #### perl test.pl test.dat #### It starts with foo. Then it goes to bar. That's it. This next line contains nothing that matches.
## perl test.pl test.dat ##
## It starts with foo. Then it goes to bar. That's it. This next line contains nothing that matches.