use strict; use warnings; use diagnostics; #For testing only a pseudo workspacepath my $Workspace = 'Workspace\\'; #This string has the substring which i want to repalce. my $string = '"_out\Dem_Deb_Cfg.h", line 189: warning #47-D: incompatible redefinition of '; if($string=~m/(\[[\S]+\.c\]|\[[\S]+\.h\]|\[[\S]+\.cpp\]|"[\S]+\.c"|"[\S]+\.h"|"[\S]+\.cpp")/i){ my $identifier = $1; chop($identifier); my $search = substr($identifier,1); my $replace = $Workspace.$search; if( not($string =~s#$search#$replace#)){ print"does not work :-( \n"; } }