my $x = 'a'; my $y = 'b'; while () { chomp; s/\b$x\b/$y/g; print "$_\n"; } __DATA__ a a a a