Unless $/ is undefined somewhere before in your code (some part you didn't show us), $text=<MAT> only reads in one line of the file - which is probably not what you want.
To read in the whole file, use something like:
my $text = do { local $/; <MAT> };