#!/usr/bin/perl -l use strict; use warnings; my ($fh1, $fh2) = map { open my $fh, '<', $_ or die "Can't open `$_': $!\n"; $fh } qw/file1.txt file2.txt/; while (<$fh1>) { chomp; my $data1 = (split /,/)[0]; seek $fh2, 0, 0; while (<$fh2>) { chomp; print $data1 if $data1 eq (split /,/)[1]; } } __END__