use IO::File; my $line = -f $file and grep { ... } IO::File->new($file)->get_lines;