use Modern::Perl; use IO::All -strict; use List::MoreUtils qw /each_array/; my @first_array = io('./first.txt')->chomp->slurp; my @second_array= io('./second.txt')->chomp->slurp; my $ea = each_array( @first_array, @second_array ); while ( my ( $first, $second ) = $ea->() ) { if ( $first ne $second ) { say 'Arrays differ at line ', $ea->('index'); say "First: $first"; say "Second: $second"; last; } }