My understanding is that you want to print the two lines after the match? Then:
use strict; use warnings; open my $fh, "<", "somefile.txt"; while(my $line = <$fh>){ if($line =~ /pattern/){ print "Matched: $line"; print $line if defined( $line = <$fh>); print $line if defined( $line = <$fh>); } } close($fh);
In reply to Re: Regex and writing lines in file
by hdb
in thread Regex and writing lines in file
by amma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |