Crawling web site

I wrote script to crawl web site by perl. It would collect A tag of html and repeat access in site to move another web site. But I can not understand reflexive, so it is inefficient. I have the second time to write perl script. This script has limitation. Only access is html files that .html extension, and the load is put to server. Last it will put out file that write A tag of html.

use strict;
use warnings;
use LWP::UserAgent;
use Encode;
use utf8;

my $long_url = "http://www.sample.com/";
my $short_url = "www.sample.com";

sub read_url
{
  my ($url) = @_;
  my $ua = LWP::UserAgent->new;
  my $res = $ua->get($url);
  my $content = $res->content;
  $content = Encode::decode("utf8", $content );
  my @match_tag = $content =~ /<a href.*?>.*?<\/a>/gm;
  return @match_tag;
}

sub next_line
{
  my (@x) = @_;
  foreach my $i(@x){
    $i = $i."\n";
    return $i;
  }
}

sub write_data
{
  my (@x) = @_;
  my @plaha;
  foreach my $i(@x){
    $i = $i."\n";
    push(@plaha,$i);
  }
    return @plaha;
}

sub read_f
{
  my ($name) = @_;
  open(IN,$name);
  my @file = <IN>;
  close(IN);
  return @file;
}

sub get_an
{
  my (@url_obj) = @_;
  my @end_list = ("html");
  my @search_list;
  for(my $j = 0;$j<$#url_obj;$j++){
     for(my $i=0;$i<=$#end_list;$i++){
        if($url_obj[$j]=~ /.*?$end_list[$i]/){
          my $much_obj =  &regula($url_obj[$j],$end_list[$i]);
          push(@search_list,$much_obj);
        }
     }
  }
  return @search_list;
}

sub regula
{
  my ($target,$word) = @_;
  my @much = $target =~ /".*?$word/gm;
  my $r = &next_line(@much);
  return $r;
}

sub dele
{
  my ($obj,@num) = @_;
  my @dele_list;
  for(my $g = 0;$g<$#num;$g++){
     push(@dele_list,split(/$obj/,$num[$g]))
  }
  return @dele_list;
}

sub marge
{
  my (@array) = @_;
  my %count;
  @array = grep {!$count{$_}++} @array;
  return @array;
}

sub rewrite_url
{
  my ($url,$short_u) = @_;
  my $check_connashi = index($url,"/");
  my $check_conma = index($url,"..");
  my $check_conma_ni = index($url,"../../");
  my $check_conma_san = index($url,"../../../");

  if($check_connashi !=-1){
    $url =~ s/\//http:\/\/$short_u\/;
  }

  if($check_conma !=-1){
    $url =~ s/../http:\/\/$short_u/;
  }elsif($check_conma_ni !=-1){
    $url =~ s/..\/../http:\/\/$short_u/;
  }elsif($check_conma_san !=-1){
    $url =~ s/..\/..\/../http:\/\/$short_u/;
  }
  return $url;
}

sub main
{
  my $resul;
  if(-f "data.txt"){
    my @file_obj = &read_f("data.txt");

    if($#file_obj){
      my @much_it = &get_an(@file_obj);
      my @clean = &dele("\"",@much_it);
      my @diffe = &marge(@clean);

      for(my $i = 0;$i<$#diffe;$i++){
         my $get_add = &rewrite_url($diffe[$i],$short_url);
         my @crawl = &read_url($get_add);
         print @crawl;
         open(OUT,">> data.txt");
         print OUT&write_data(@crawl);
         close(OUT);
      }
    }
    $resul = "add";
  }else{
       my @crawl = &read_url($long_url);
       open(OUT,"> data.txt");
       print OUT&write_data(@crawl);
       close(OUT);
       $resul = "new";
       return $resul;
  }
  return $resul;
}

print &main();