chomp( my @array = ); foreach my $previous_line_no ( 0 .. $#array ) { # count through the array. # runs over its boundary, hmm. # see with warnings on. my $line_no = $previous_line_no + 1; if ( $array[$line_no] =~ m/fail/ ) { splice( @array, $previous_line_no, 1 ); # take that previous line out. } }