while (<>){ my @arr=split('#'); chomp(@arr); my $n=0; system("cat ff/$arr[0].xml >temp"); open FILE, "temp" or die $!; while(){ if($n==1){$n=0;print "matched previously but now second line $_";} else { if (/$arr[2].*$\n/g) { if (($`=="") && $n==0)) { print "matched but text on next line";$n=1; } else { print "matched: $` \n";};};print "\r\n "; }; }; }; system("rm temp"); };