while (defined my $line = ) { # read all data in one while(){} chomp $line; # remove \n from the end of the line next if $line eq ''; # skip empty lines ... }