use warnings; use strict; use Fatal qw/ open close /; use File::Set; sub cback { my ($context, $prefix, $fpath, $ftype, $stat) = @_; if ($ftype eq 'f') { open my $fh, '<', $fpath; my $first_line = <$fh>; print $first_line; } } my $fs = File::Set->new(); $fs->add('/some/dir'); $fs->list('',\&cback);