#!/usr/bin/perl use strict; use warnings; use Tie::File; my $file = '/path/to/file.ext'; my @unwanted = qw(ICT ProgramVariables); tie my @lines, 'Tie::File', $file or die $!; @lines = grep{ my $i = $_; grep{$i =~ /^\Q$_\E/;}@unwanted }@lines; untie @lines;