$line =~ s/input(?= .*clk)/output/g; [download]
Untested since no test cases were provided.
In reply to Re^3: Search and replace by tybalt89 in thread Search and replace by kulua