use strict; use warnings; my $line = "System has tool zigzag version 3.6"; my $match = 'System\s+has\s+tool\s+([0-9a-zA-Z_-]+)\s+version\s+(.*)'; my $replace = '"System has tool $1 version ABC"'; $line =~ s/$match/$replace/eeg; print "Line after replacement: $line \n";