#!/bin/sh perl -i~ -e ' # -i~ for in-place editing with tilde backup use strict; use warnings; my @a; my %excludehash; my $file = shift; open(excludelist, "< $file") or die; chomp( @a= ); close(excludelist); @excludehash{@a}=@a; { local($/) = ""; while (<>) { m/YOURKEY:\s+(.*)$/m; print unless exists $excludehash{ $1 } } }' "excludefile" "datafile"