#!/usr/bin/perl use strict; use warnings; my $str = 'hello nr34 , 56, hi'; print "input string=$str\n"; $str =~ s/.*nr(\d+)([^\d]+)(\d+)(.*)/"calc(nr$1)$2".eval{$3*4}."$4";/e; print "output string=$str\n"; __END__ Prints: input string=hello nr34 , 56, hi output string=calc(nr34) , 224, hi