sub read_line { my $h = shift; local $/ = "\n"; return <$h> } sub read_para { my $h = shift; local $/ = ""; return <$h>; } use Fatal qw(open); open H, '<', 'files.csv'; while (my $txt = read_file(*H)) { # process the CSV line and make the filename available in $fn open TXT, '<', $fn; my @paragraphs = read_para(*TXT); # process }