my $tp = Time::Piece->strptime($1, DATE_FORMAT); # out the replacement line print "tp is: $tp\n"; # we check $tp values here, just for the record ($tp+ONE_MINUTE*2*$n)->strftime(DATE_FORMAT); #### $tp = $tp+ONE_MINUTE*2*$n; print "tp is now: $tp\n"; # we check $tp again after the changes $lines[1] =~ 's{:20140924105028(\d+)}'{$tp}e;