my ($fn) = $address =~ /^\W?(\w+)/; return unless defined $fn and length $fn; # I would not test -f or -r or -e manually. # If open failed, the reason is in $!. open my $fh, "~/.quotes/$fn" or do { warn "Cannot open $fn for reading ($!).\n"; return; } local $/ = "\n%\n"; my $quote; rand($.) < 1 && ($quote = $_) while <>; chomp $quote; $window->command("msg $channel $nick> $quote") for split /\n/, $quote;