#!/usr/bin/perl -w use strict; die "Usage: $0 infile1 infile2\n" unless (@ARGV==2 and -f $ARGV[0]); my ($infile1, $infile2) = @ARGV; open( READDATA, $infile1 ) or die "Cannot open $infile1: $!\n"; my %h = (); while () { if ( /(\d{4}\w\d?)\s+(\w*)/ ){ my ( $port, $lsn ) = ( $1, $2 ); $h{$port} = $lsn; } } close READDATA; open( READDATA2, $infile2 ) or die "Cannot open $infile2: $!\n"; while () { chomp; if ( /(\d{4}\w\d?)/ and exists( $h{$1} )) { print "$_,$h{$1}\n"; } }