in reply to functional "given...when..."?

You can of course write:
my $suffix = $type ~~ "csv" ? "txt" : $type ~~ "xml" ? "xml" : ....;
No do, no extra variable.