class Line { has $.str handles 'words'; method Str { self.words.reverse.join(' ') } } multi infix:(Line $a, Line $b) { $a.words[*-1] <=> $b.words[*-1] || $a.words[0] <=> $b.words[0]; } print lines().map({Line.new(str => $_)}).grep(/SRC1/).sort;