# disclaimer - assume use strict and warnings are both in effect, and # variables are lexically named elsewhere.. this is a toss off bit o' code while (my $line = ) { $test =~ join ( split ( /(?:[^A-Z])/, $line ) ); # the previous line will excise any non uppercase, non letters from $line # now, we compare $line to our $foo while ($test =~ /$foo/g ) { $line =~ s/$1/(stuff1 . $1 . $stuff2)/e } }