use warnings; use strict; my $test = 'x x x a x x x b x x x a x x x b x x x'; warn $test; (my $res = $test) =~ y/[ab]/[ba]/; warn $res;