#!/usr/bin/perl use strict; use warnings; open( A, '<', 'DUMP_A' ) or die "Could not open file\n"; open( B, '<', 'DUMP_B' ) or die "Could not open file\n"; open( OUTPUT, '>', 'INACTIVE_LIST' ) or die "Could not write to file\n"; my $readA; my $readB; while ( defined( $readA = ) ) { $readA =~ s/\s+//g; my $a_ID = $readA; while ( defined( $readB = ) ) { chomp($readB); my ( $b_ID, $b_acctno ) = split( /\|/, $readB ); if ( $a_ID =~ /^$b_ID/i ) { print OUTPUT "$a_ID|$b_ID \n"; } } seek( B, 0, 0 ); } close OUTPUT; close A; close B;