#!/usr/bin/perl -w use strict; my $words='test Buffy testament Anya tot Willow tesseract Faith tent this is a problem right?'; $words =~ s/\b(t[^t\s]+t)\b/$1 eq "test" ? $1 : ''/ge; print $words;