#!/usr/bin/perl use warnings; use strict; my $fh; # Reading one line from "test.json": open($fh, "<", "test.json") or die; my $JSON_DATA = <$fh>; chomp($JSON_DATA); close($fh); my $WEBADDRESS; my $ip = "5.5.5.5"; if ($JSON_DATA -ne "") { $WEBADDRESS="webaddress:jq.webaddress" . $JSON_DATA; $JSON_DATA =~ s/$WEBADDRESS/webaddress\:$ip/g; # Writing to "test.json": open($fh, ">", "test.json") or die; print $fh $JSON_DATA; close($fh); }