This would be efficient (could use rindex if there is just a
short path after the web part for even more efficiency but then you'd
run into trouble with users having another 'web' subdir,so I'd
recommend this):
#!/usr/bin/perl -w
use strict;
my $FileName='/home/sites/site18/users/rjoseph/web/images/image1.jpg';
my $Stripped=substr $FileName,0,index($FileName,'web');
print "Stripped to: $Stripped\n";