in reply to perl pattern match for end of string using STDIN and chomp

You are mistaken. Your first program works fine for the input you specified:
$ perl 800041a.pl get some string: /xxxx/yyyy/ZZZ_xxxx.CCC ZZZ CCC /xxxx/yyyy/ZZZ_xxxx

Note that you probably want to use \Q$type\E in patterns, not just $type, since $type doesn't contains a regex pattern but text to match literally.