use strict; use warnings; open my $fh, '<', 'source.txt'; my @files = <$fh>; chomp @files; print join "\n", grep { -e $_ } @files;