use strict; # always do this my $line; # this will contain the current line read # from stdin. We could also have used $_, # but using $line is less cryptic my $counter = 1; # This is the counter of the urlXX= string while (<>) { # while we get input, we read it $line = $_; # Munge the current line into what we want $line =~ s!^http://!url$counter=http://!i; # BastardOperator made a post below that got me thinking. # Maybe you want it this way : $line =~ s!&!item=!g; # but maybe you want item1=bla item2=ble etc. # This line will do the second : my $itemcount = 1; while ($line =~ s/&/$itemcount++/e) { # the action is in the while statement } # and print it print $line; # and increment our counter $counter++; };