$ perl -i.bak -ne 'print unless /(?:Module1|Module2)/' Snapshot.pm #### #filter_snapshot.pl use strict; use warnings; my @exclude_modules = map {chomp;quotemeta($_)} ; FILTER: while (<>) { for my $excluded (@exclude_modules) { next FILTER if /$excluded/ } print ; } __DATA__ module1 Module2 Module3::SubModule Module4 #### $ perl filter_snapshot.pl Snapshot.pm > New_Snapshot.pm