in reply to optimize the code

First, always use strictures like this:
#!/usr/bin/perl use strict; use warnings; use Date::Manip;
Second, fix your lexical problem. For example,
$date_two_days_ago = ParseDate('3 days ago');
should be
my $date_two_days_ago = ParseDate('3 days ago');
Third, you used $arr[3] but forgot to give the array.
Fourth, run perltidy to cleanup. Here's what I got:
#!/usr/bin/perl use strict; use warnings; use Date::Manip; my $date_2_days_ago = ParseDate('3 days ago'); my $date_converted = UnixDate( $date_2_days_ago, '%e/%h/%Y' ); open DATA, '>', $ARGV[1]; open FH, $ARGV[0]; while (<FH>) { my(@tab_delimited_array) = split( /\t/, $_ ); $tab_delimited_array[3] =~ s/^\[//; $tab_delimited_array[3] =~ s/^\-//; chomp $tab_delimited_array[3]; if ( length $tab_delimited_array[3] > 1 ) { my $date_format = UnixDate( $tab_delimited_array[3], '%Y%m%d%H +:%M:%S' ); my $converted_date = Date_ConvTZ( $date_format, 'GMT', 'PST' ) +; my $pst_converted_date = UnixDate( $converted_date, '%e/%h/%Y: +%H:%M:%S' ); $pst_converted_date =~ s/^\s//g; my $extracted_YMD = UnixDate( $converted_date, '%e/%h/%Y' ); my @arr; $_ =~ s/$arr[3]/$pst_converted_date/g; if ( $extracted_YMD =~ /$date_converted/ ) { print DATA $_; } } } close DATA; close FH; __DATA__