#!/usr/bin/perl -w use strict; my @lines = <>; print $_ foreach sort {length($a) <=> length($b) or $a cmp $b} @lines;