use strict; use warnings; use DateTime; use DateTime::Set; use DateTime::Format::Natural; use DateTime::Format::Oracle; $ENV{'NLS_DATE_FORMAT'} = 'DD.MM.YYYY HH24:MI'; my $step = 1; # one day one jump my $dt_from = DateTime->new( year => 2017, month => 10, day => 16, hour => 16, time_zone => 'Asia/Taipei', ); my $dt_to = DateTime->new( year => 2017, month => 10, day => 17, hour => 16, time_zone => 'Asia/Taipei', ); my $dt_next = $dt_from->clone->add(hours => $step); $dt_next = $dt_to->clone if $dt_next > $dt_to; while( $dt_next <= $dt_to){ my $string_from = DateTime::Format::Oracle->format_datetime($dt_from); my $string_next = DateTime::Format::Oracle->format_datetime($dt_next); print " from $string_from to $string_next \n"; my $indivparam_string = 'AutoE=1~AutoS=A~AutoT=1~TFrom=29.12.2017 06:40:30.000 SDT Greenwich Standard Time~TTill=29.12.2017 16:00:00.000 SDT Greenwich Standard Time~PLSType=0~GroupID=5922~ChkGrp=1~JobDefRegisterSets=~'; print "old indiv string is $indivparam_string !!\n"; ###########################################just for some case, you have to modify conn string directly##################### $indivparam_string =~ s/From=\K\d\d\.\d\d\.\d{4}\s\d\d:\d\d:\d\d/$string_from/; $indivparam_string =~ s/Till=\K\d\d\.\d\d\.\d{4}\s\d\d:\d\d:\d\d/$string_next/; print "new indiv string is $indivparam_string !!\n"; last if $dt_next == $dt_to; $dt_from = $dt_next->clone; $dt_next->add(hours => 1); $dt_next=$dt_to if $dt_next->clone->add(hours => 1) > $dt_to; }