for ($etime){ my ($dd,$hh,$mm,$ss)=() # see man ps etime looks like [[dd-]hh:]mm:ss if ( /^(?:(?:(\d{1,2})-){0,1})(?:(?:(\d{2}):){0,1})(\d{1,2}):(\d{2})$/ ){ $dd = $1 || ''; $hh = $2 || ''; $mm = $3; $ss = $4; $etime_secs= $ss+($mm*60)+($hh*60*60)+($dd*24*60*60); } } #### for ($etime){ # see man ps etime looks like [[dd-]hh:]mm:ss # if either $dd and $hh are not present then they will eat # up the $mm & $ss so split on a non digit and reverse it: my ($ss, $mm, $hh, $dd)= reverse split /\D/; $hh += 0; # stop warning as $hh may not be initialised $dd += 0; # same as $hh :) $etime_secs= $ss+($mm*60)+($hh*60*60)+($dd*24*60*60); }