perl one-liner: how to convert file or stream to upper or lower case

So you want to convert a file/stream to upper or lower case in Linux? piece of cake, there are thousands of ways to do that. Usually I leverage tr

convert to upper case:

cat filename | tr "[:lower:]" "[:upper:]"

convert to lower case:

cat filename | tr "[:upper:]" "[:lower:]"

I am sort of tired of tr and was looking for way to use perl, here is my hack:

convert to upper case:

perl -wpl -e 's/^.*$/\U$&/g;' filename

convert to lower case:

perl -wpl -e 's/^.*$/\U$&/g;' filename

It basically match anything (*) in between the beginning (^) and the end ($), substitute (/s) just the same string by applying the modifier, \L (lower case) and \U (upper case). Not necessarily easier than using tr, just an attempt with perl oneliner. Remember TMTOWTDI? Yeah, "There's more than one way to do it".

^ Top of Page