#! /usr/bin/perl -w
use strict;
# Read whole file into a list, this could be an open()ed filehandle
# instead of the DATA section from below
my @lines = <DATA>;
# Sort the list by comparing the numeric portion of the lines
my @sorted = sort {
my ($numA) = $a =~ /^(\d+).*/;
my ($numB) = $b =~ /^(\d+).*/;
$numA <=> $numB
} @lines;
# Output the sorted list
{
# We never chomped, the lines still contain newlines,
# so don't need a list separator
local $" = "";
print "@sorted";
}
__DATA__
1260896 abadeno
972 achin00
402 astamen
181847 azeleke
134 b005376
1 b005824