use warnings; use strict; while () { my $pat = $_; $pat =~ s/_x_x$//i; #This is not working. $pat =~ s/_x_s$//i; #This is working. $pat =~ s/_x$//i; #This is not working. print $pat; } __DATA__ foo_x_x boo_x_s moo_x #### foo boo moo