Well here is a 2 step solution. It still may have a problem if you encounter lines with 2 or more 'it' in them. Its called regex greediness. See greediness . I leave you some work to fix the possible greediness issue. :-)
#!/usr/bin/perl
use strict;
use warnings;
while (<DATA>) {
if ( $_ =~ m/([?.,]$)/){
# print " matching first criteria $_";
#now check for 'it', using capture parenthesis
#for the text before and after 'it'
if ( $_ =~ m/(.*)it(.*)/ ){
print "$2\n"; # the second capture parenthesis
}
};
}
__DATA__
4 score, and 7 years ago?
our ? forefathers came,
upon it -- a continent.
it was it was it ? foo?
.bar bazz
__END__
|