open(my $fh, '<', 'theinputfile.txt') or die "Unable to open theinputfile.txt, $!\n"; while(my $var = <$fh>) { # Reading each line one by one from theinputfile.txt into $var chomp($var); # chomp $var not $_ since $_ isn't used #change token in url query string to $var $urlChop[1] =~ s/MATCH/$var/; # replace with $var not $_ since $_ isn't used # ... whatever else you need to do }