use strict; use warnings; use feature 'say'; my @files = ( 'log4perl.Advanced1999:06:56:12.General_Information.ErrorLog', 'log4perl.Advanced1999:06:56:12CSS.General_Information-collector-2.ErrorLog', 'log4perl.Advanced1999:06:56:12CSS.General_Information-collector-2.INVALID', ); for (@files) { if (/ ^ [\w_-]+ \. [\w:]+ \. [\w_-]+ \. ErrorLog $ /x) { s/ ^ ([\w_-]+) \. ([\w:]+) CSS \. /$1.$2./x; say; } } #### 13:43 >perl 1783_SoPW.pl log4perl.Advanced1999:06:56:12.General_Information.ErrorLog log4perl.Advanced1999:06:56:12.General_Information-collector-2.ErrorLog 13:43 >