It's not clear from the context, but are you just looking for set intersection? I mean, if the comparison is merely "is this line of B also a line in A in its entirety", then the problem is trivial:
open A, "a" or die;
my %in_a = map { $_, 1 } <A>;
open B, "b" or die;
while (<B>) {
print if $in_a{$_};
}