open IN_FILE, "<$filename" or die "Cannot open $filename for reading\n"; my @file = ; close IN_FILE; for (my $i = 0; $i < $#file; $i++) { # Do your stuff here. # If you end up changing the number of lines, back up $i and # go through indices again. }