use strict; use warnings; my $file1 = <) { chomp; next if ! $_; if (/parcel#\s+(\d+)/) { $currParcel = $1; next; } next if ! defined $currParcel || ! /^doc num (\d+)/; $docs{$1} = $currParcel; } close $f1In; open my $f2In, '<', \$file2; while (<$f2In>) { chomp; next if ! /doc num\s+(\d+)\s+(.*)/; if (! exists $docs{$1}) { warn "Parcel not known for $1\n"; next; } print "parcel# $docs{$1} doc num $1 $2\n"; } close $f2In;