#!/usr/bin/perl # randline.pl - which is the same as the one-liner # perl -e 'rand($.) < 1 && ($p = $_) while <>; print $p' while ( $line = readline ) { if ( rand($.) < 1 ) { $pick = $line; } } print $pick;