while(<>){ if (/^[0-9]+, |Sent:/){ push (@logs, $_); } } print $logs[0]; print $logs[1];