# Read multiple lines from multiple files at the same time my @files = @ARGV; my @fh; my $i = 0; foreach my $file (@files) { -f -r $file or next; open $fh[$i++], '<', $file or die "Cannot open $file: $!"; } while (1) { my @lines; foreach my $i (0 .. $#fh) { ref $fh[$i] eq 'GLOB' or next; push @lines, scalar readline $fh[$i]; if (eof $fh[$i]) { close $fh[$i]; $fh[$i] = undef; } } @lines or last; foreach my $line (@lines) { # do something with $line } }