local $/ ; while (1) { $/ = "#" ; my $line1 = ; $/ = "?" ; my $line2 = ; last if (!defined($line1) && !defined($line2)) ; foo($line1, $line2) ; } ;