$previous = ($start-$show); unless($previous < 1){ # unless we're already at the beginning print qq~ Previous $show~; } $next = ($start+$show); unless($next > $c){ # unless we're already at the end print qq~ Next $show~; }