$output=''; while($_=~/\A([S\-\+XIO]+)\z/g) { $part=$1; $output=$output.$part; } print "$output\n";