A typical algorithm to find the last entry in a data-structure that you can only read sequentially from the beginning is the following:
- create a variable for your result (e.g. my $last_baki = "no baki there";)
- use a loop to read the whole data-structure element-by-element (in your case: line-by-line)
- if the element matches your requirements (in your case: contains the word baki), overwrite the result-variable with this element
- when you have finished your loop, the result-variable will contain the last matching entry
HTH, Rata