my( $lineA, $lineB ); while( 1 ) { $lineA= do { while(){ last if /\S/ }; $_ }; $lineB= do { while(){ last if /\S/ }; $_ }; last if ! defined $lineA || ! defined $lineB; for( $lineA, $lineB ) { s/\s+/ /g; s/^ //; s/ $//; $_= lc $_; } last if $lineA ne $lineB; } if( defined($lineA) || defined($lineB) ) { warn "The files are different!\n"; }