#!/usr/bin/perl -w use strict; /^t(?!est\b)\w*t$/ and print while ; __DATA__ test testset tot tesset tt #### #!/usr/bin/perl -lw use strict; $_ = "thought test tot 1 2 3 tesset"; s/t(?!est\b)\w*t\s*//g; print;