my @lines = <$filehandle>; # read all lines s/\s+$// for @lines; # remove any whitespace at the end of each line.