The study of bubble dynamics is important in various engineering applications as it can provide a fundamental understanding of the bubbly flow behavior. This paper presents a novel method for tracking bubble trajectories and classifying bubble behaviors, including formation, extinction, continuous movement, fragmentation, and coalescence. The method is based on the theory of perfect matching in bipartite graphs. By establishing the perfect matching between bubbles identified at adjacent time instants, judging the continuity of bubble motion, and simply calculating the number of bubbles in the neighbor of matching bubbles at adjacent time instants, the method can deal with the challenging situation where the bubble position and volume significantly change between two adjacent time instants. The method is validated in a simulated vertical pipe boiling flow, showing that the tracking accuracy is 100% and classification accuracies for continuous movement, fragmentation, and coalescence events are estimated to be larger than 90% in a wide range of time steps between two adjacent time instants.