use 5.010; while (<>) { my $p = /=/p ? ${^POSTMATCH} : next; next if (my $c = <>) =~ /=/p and $p eq ${^POSTMATCH}; say $_, $c; }