my $status = shift @cells; my $end = pop @cells; my $start = pop @cells; print "$_" for ($status, join(' ', @cells), $start, $end); #### # Do this once: my $status_re = qr{\w+}; my $date_re = qr{\d{2}-\w{3}-\d{4}}; my $log_re = qr{^($status_re)\s+(.*?)\s+($date_re)\s+($date_re)\R$}; ... # Do this in the while loop print "$_" for $line =~ $log_re;