my $new_act; my $new_scene; while (<$playIn>) { my $line = $_; ... # Print the act heading if we haven't yet. if ($new_act) { print "$new_act\n"; $new_act = undef; } # Print the scene headin if we haven't yet. if ($new_scene) { print "$new_scene\n"; $new_scene = undef; } ... # Step 1.6: We should also print act headings. elsif ($line =~ m/.*