use strict; use warnings; use Data::Dumper; my ($file_1, $file_2) = ('output1.csv', 'output2.csv'); open my $fh, '<', $file_1 or die "Can't open $file_1: $!"; my %first = map { chomp; split /\s*,\s*/ } <$fh>; print Dumper( \%first ) ; open $fh, '<', $file_2 or die "Can't open $file_2: $!"; my %second = map { chomp; (split /\s*,\s*/)[1,2] } <$fh>; print Dumper( \%second ) ; foreach my $name (sort keys %first) { if (not exists $second{$name}) { print "Devices should be added: $name\n"; next; } if ($first{$name} eq $second{$name}) { print "Match found $name, $first{$name}\n"; } else { print "UPDATE need be done for $second{$name}\n"; open ( my $input_1, '<', 'output1.csv' ) or die $!; while ( <$input_1> ) { chomp; print " input_1 = $_\n" ; my ($name_1, $ip_1) = split /,/; print " (1) $name, $ip_1\n" ; (my $id, $first{$name}, $second{$name}) = split /,/; print " (2) $id, $first{$name}, $second{$name}\n" ; } } }