sub myfunc { my ($ts, $interval) = @_; my $minute; # # Somehow get $minute from $ts, # using the method of your choice. # # Ex., using the method in the OP... $minute = substr($ts, 10, 2); return $interval * int($minute / $interval); }