#initialize a value to count where we are in the array in order to #delete the lines we do not need foreach my $index ( reverse 0 .. $#data_file ) { foreach my $item ( @lines ) { if ( $data_file[ $index ] =~ /\Q$item/ ) { splice @data_file, $index, 1; } } }