use strict; use warnings; use Term::ANSIColor; my $t = "ACGCGATAGCATTAGACCTGGCACAGT"; my @highlights = ( # [ start, len, color ] [ 20, 5, 'bold blue' ], [ 10, 2, 'bold red' ], [ 3, 4, 'bold green' ], ); for my $ar (@highlights) { my ($start, $len, $color) = @$ar; $t = substr($t, 0, $start-1) # first part . colored(substr($t,$start,$len), $color) # colored part . substr($t,$start+$len); # final part } print $t, "\n";