use Tie::File; tie my @array, 'Tie::File', 'filename' or die $!; @array = grep { not m/^ICT/ and not m/^ProgramVariables/ } @array; untie @array; # all finished