$str = 'maketools/lastproj (test) OK (20:20:56 - 20:20:50)'; $str =~ s/^.*(\d{2}:\d{2}:\d{2})\).*$/$1/; printf("$str\n");