$ echo ' Dear Monks, I want to sort the attribute values inside and remove the commas. i.e. input: some other text output: some other text test.txt: some other text ' | perl -e' $/ = ">"; while ( <> ) { s{()\z}{$1@{[ sort { $a <=> $b } $2 =~ /\d+/g ]}$3}; print; } ' Dear Monks, I want to sort the attribute values inside and remove the commas. i.e. input: some other text output: some other text test.txt: some other text