#!/usr/bin/perl -lw use strict; # here is one thing you might want sub what { my $what = shift; return ($what - 5); } my $string = 'a and a b and a 5 and a 6 and a 8 an what?'; print $string; $string =~ s/(\d)/&what($1)/ge;