my $file = 'D:/htmladdresses.txt'; open my $input_fh, '<', $file or die "Can't open '$file' for reading: $!"; while (my $input = <$input_fh>) { chomp $input; # Use $input here as you were previously using it } close $input_fh;