#!/usr/bin/perl my $line = "System has tool zigzag version 3.6"; my $match = 'System\s+has\s+tool\s+(\w)\s+version\s+(.*)'; my $replace = '"System has tool $1 version ABC"'; $line =~ s/$match/$replace/eg; print "Line after replacement: $line \n"