in reply to Re^2: Lost in Perl - text file searching and printing
in thread Lost in Perl - text file searching and printing

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__

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh