# Initialize array @lines my @lines; while () { # Add line from file to array @lines if line starts with # digit push @lines, $_ if m/^\d/; } # Print array @lines after all processing has been done. print @lines;