#!/usr/bin/perl $on = 1; while () { $line = $_; if (/^#%id=/) { chop($id = $'); $on = 1; for (@ARGV) { if ($_ =~ /^!/) { $on = 0 if $id =~ $'; } else { $on = 0 unless $id =~ $_; } } } print $line if $on; }