.. my $list_file = '/path/to/list.txt'; open my $read, '<', $list_file or die "cannot read from'$list_file'!"; while (<$read>){ # it populates $_ is the same of: defined $_ = <$read> chomp; my $ret = process ($_) if -e "./$_"; if ($ret){print "$_ succesfully processed\n"} else{print "Warning: '$_' was not processed!\n"} } sub process{ my $file = shift; open ... or return 0 # read and do something close .. # implicitly return the last thing: if close succeded is 1 }