(Replying to all this time, oops) >From the above: $ perl -ne'rand++$n<1?$s=$_:1;END{print$s}' <alpha.html No need to increment a counter like $n, just use $. which gives the line number 1 indexed. $ perl -ne'rand$.<1?$a=$_:1;END{print$a}' <alpha.html Also replaced $s with $a so it runs safe under 'warnings'. ;) Two more characters saved.