perl -ni.bak -e "if(/10/){@buf=();$cnt=0;while(<> and $cnt++<2){}}else{push @buf,$_;if(defined $buf[5]){print shift(@buf)}}END{print @buf}" mytest.txt