use strict; use warnings; sub firstline { open (my $in, shift) && return scalar <$in>; # no close() required } print firstline("/etc/hosts");