while (my $line = <$input>) { if ($line =~ /^XXX$/) { print "\n"; } else { chomp $line; print $line; } } print "\n"; #may need a final one of these