The obvious (to me) modest improvement is to change the main loop so that you're only keeping in
%master those things that you need to delete from
%slave later (since that's all you're doing with it, anyway). For clarity, you should rename
%master to
%common.
my (%common, %slave);
%slave = map {chomp; $_ => undef} <SLAVE>;
while ( <MASTER> ) {
chomp;
if (exists $slave{$_}) { $common{$_} = undef }
else { print "$_ exists on master but not slave\n" }
}
delete @slave{ keys %common };
print "$_ exists on slave but not master\n" for keys %slave;
The PerlMonk tr/// Advocate