while (my $line = <>) { chomp($line); while ( length( $line ) ) { if ( my $not_curly = /^([^{]+)/ ) { push @tokens, process_not_curly($not_curly); $line = adjust_line($line, $not_curly); } elsif ( my $curly = /^\{([^}]+)\}/ ) { push @tokens, process_curly($curly); $line = adjust_line($line, $curly); } else { die "can't get here, "; } } }