sub f{join"",sort split//,pop};$w=f($/.pop);die grep f($_)eq$w,<>