#!/usr/bin/perl -l print for map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [$_, ( /blahblah/ ? 0 : 1 ) . $_] } <>;