You need to keep some state, and use that to determine what to print out the second (or third, or…) time around.
my $has_printed_once = 0;
# your loop {
if ($type eq $kind) {
# no change
} else {
if ($has_printed_once == 0) {
# print the second thing
} else {
$has_printed_once = 1;
# print the first thing
}
}
# } close loop
solved Detecting when an else block gets executed for the second time [closed]