#!/usr/bin/perl -w use strict; my $passwords = 'passwords'; # It would be better to cache the $count value in a separate file my $count = `wc -l $passwords`; # Bail out if wc failed exit if $?; # Get the line count $count = (split ' ', $count)[0]; # Bail out if the file is empty die "No passwords in $passwords\n" unless $count; my $key = 1 + int rand $count; my $password; # Localised in-place edit { local $^I = ''; local @ARGV = $passwords; while (<>) { if ($. == $key) { chomp; $password = $_; } else { print; } } } print $password, "\n"; __END__