#!/usr/bin/perl use strict; use warnings; my @array=qw/a b c d/; while ( @array > 1 ) { my $first = shift(@array); for my $next ( @array ) { # take diff $first - $next; # take product $first * $next; print sprintf("%-8s%s\n","$first - $next","$first * $next"); } } exit; __END__ a - b a * b a - c a * c a - d a * d b - c b * c b - d b * d c - d c * d