#!/usr/bin/perl -w use strict; open (my $fh1, '<', "testa.txt") or die "cannot open testa"; open (my $fh2, '<', "testb.txt") or die "cannot open testb"; while ( defined (my $test1 = <$fh1>) and defined (my $test2 = <$fh2>) ) { print "both defined\n"; }