文字コードの変換を試してみる

#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
use Encode;

my $url = 'http://www.excite.co.jp/';
my $filename = 'sample.html';

# WEB ページを取得する
my $body = get($url);
# 入力されるデータの文字コードを指定
$body = decode('shiftjis', $body);
open(my $fh, ">", $filename);
# 出力されるデータの文字コードを指定
print $fh encode('eucjp', $body);
close $fh;

直接ファイルに書き込んでしまう場合

特に指定しなくても入力元の文字コードで、ファイルに保存されていた。

#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
use utf8;

my $url = 'http://www.excite.co.jp/';

# WEB ページを保存する
# 保存された WEB ページの文字コードはオリジナルと同じ
getstore($url, 'index.html');