#!/usr/bin/perl
use strict;
use warnings;
open my $a, '<', 'a.txt' or die;
open my $b, '<', 'b.txt' or die;
my %ids = map { $_ => 1 } map { (split /,/)[0] } <$b>;
while (<$a>) {
    my $id = (split /,/)[0];
    print if $ids{$id};
}