#! /usr/bin/perl use strict; use warnings; my $file; while () { if (/^[^+-]/) { $file=$_; next; } my $match; for my $arg (@ARGV) { $match=1 if /\Q$arg\E/; } next if !$match; if (defined $file) { print $file; $file=undef; } print; }