use strict; $| = 1; use utf8; use Encode qw( encode decode ); use URI::Escape; use LWP::UserAgent; my $ua = new LWP::UserAgent; $ua->agent( "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)" ); my @keywords = ( '人生とは' ); my $keyword_0; my $keyword_1; while ( 1 ) { $keyword_0 = ''; $keyword_1 = pop( @keywords ); print encode( 'sjis', $keyword_1 ); while ( 1 ) { my $keyword_n; my $keyword = $keyword_0. $keyword_1; # print "\n".encode( 'sjis', $keyword )."\n"; # print "."; my $text = decode( 'utf8', $ua->get( "http://www.google.com/search?ie=UTF-8&q=". uri_escape( encode( 'utf8', $keyword ) ) )->as_string() ); $text =~ s/<[^>]*>//go; while ( $text =~ /$keyword(\p{Han}+|[\p{Hiragana}ー]+|[\p{Katakana}ー]+)/g ) { if ( length( $1 ) < 8 ) { $keyword_n = $1; push( @keywords, $keyword_n ) if( $keyword_n !~ /\p{Hiragana}/ ); last; } } unless ( $keyword_n ) { print encode( 'sjis', '。' ); last; } else { print encode( 'sjis', $keyword_n ); } $keyword_0 = $keyword_1; $keyword_1 = $keyword_n; } }