#!/usr/bin/perl use strict; use warnings; die "Usage: $0 []\n" unless @ARGV; my %id_hit=map { substr($_, 0, 6) => 1 } do { my $idfile=shift; open my $fh, '<', $idfile or die "Can't open `$idfile': $!\n"; <$idfile>; }; while (<>) { if (/([A-Z]\d{5})/ and $id_hit{$1}) { defined(my $next=<>) or die "No 'next' line in `$ARGV' at line $.\n"; print $next; } } __END__